Pre-routing with querystrings with Express in Node JS

后端 未结 2 777
借酒劲吻你
借酒劲吻你 2020-12-19 06:35

I\'m trying to use express to parse the querystring in case certain parameters are set and execute a little piece of code, before the actual routing is happening. The use-ca

2条回答
  •  情话喂你
    2020-12-19 07:11

    express does not allow you to route based on query strings. You could add some middleware which performs some operation if the relevant parameter is present;

    app.use(function (req, res, next) {
        if (req.query.something) {
            // Do something; call next() when done.
        } else {
            next();
        }
    });
    
    app.get('/someroute', function (req, res, next) {
        // Assume your query params have been processed
    });
    

提交回复
热议问题