Wildcard in Express/node.js router

后端 未结 2 1312
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-11 19:27

I would like to \"get rid\" of the router in node.js. Currently, what I have is something that looks like this:

app.get \'/thing1\', (req, res) ->
    re         


        
相关标签:
2条回答
  • 2021-01-11 20:27

    From http://expressjs.com/api.html#app.VERB :

    app.get(/^(.*)$/, function(req, res, next){
      res.send(req.params[0]);
    });
    

    Working gist: https://gist.github.com/elliotf/5826944

    0 讨论(0)
  • 2021-01-11 20:32
    app.get('/:thing', function (req, res) {
      res.render(req.params.thing)
    })
    
    0 讨论(0)
提交回复
热议问题