Sub-Folder style routing in Express

前端 未结 1 1791
挽巷
挽巷 2020-12-16 07:34

I want to parse simple routes like these:

http://example.com/foo/bar/baz/

where there is no theoretical limitation to the number of them. A

相关标签:
1条回答
  • 2020-12-16 08:23

    Use a regular expression.

    app.get(/^\/((?:[^\/]+\/?)+)\//, function(req, res) {
      res.send(req.params[0].split('/'));
    });
    
    app.listen(8080);
    

    Run it and then

    $ curl localhost:8080/foo/bar/baz/
    ["foo","bar","baz"]
    
    0 讨论(0)
提交回复
热议问题