Difficulty with absolute and relative paths in Express

后端 未结 5 680
挽巷
挽巷 2021-01-24 17:59

I have a route for an API in an Express app that looks like this:

app.get(\'/:username/:bookmark/\', function(req, res) {

  // do stuff

})

As

5条回答
  •  猫巷女王i
    2021-01-24 18:43

    When using try:

    app.get("/:username/:bookmark/", function(req, res) {});
    

    With the : you do not state which path you get, but it will get all paths and you know what the path is if you type req.params.username or req.params.bookmark. If you want the path to /username/bookmark/ you must do this:

    app.get("/username/bookmark/", function() {});
        //Do something
    });
    

提交回复
热议问题