Express.js multiple methods

前端 未结 4 2122
别跟我提以往
别跟我提以往 2021-01-12 02:30

So in Express you can do:

app.get(\'/logo/:version/:name\', function (req, res, next) {
    // Do something
}    

and

app.a         


        
4条回答
  •  我在风中等你
    2021-01-12 03:18

    You can also use the array spread operator if your route pattern is the same for multiple methods.

    e.g.

    const route = [
        '/logo/:version/:name', 
        function handleRequest(req, res) {
            // handle request
        }
    ];
    
    app.get(...route);
    app.post(...route);
    

提交回复
热议问题