express.js - single routing handler for multiple routes in a single line

后端 未结 5 852
悲&欢浪女
悲&欢浪女 2020-12-02 05:55

Is there a way to make this on a single function call?

var todo = function (req, res){};

app.get(\"/\", todo);
app.get(\"/blabla\", todo);
app.get(\"/blabla         


        
5条回答
  •  粉色の甜心
    2020-12-02 06:06

    I went for a:

    ['path', 'altPath'].forEach(function(path) {
      app.get(path, function(req, res) { etc. });
    });
    

提交回复
热议问题