Modifying Express.js Request Object

前端 未结 5 2081
既然无缘
既然无缘 2021-01-01 09:14

In express.js, I would like to provide an additional attribute on the request object for each of my URI listeners. This would provide the protocol, hostname, and port number

5条回答
  •  Happy的楠姐
    2021-01-01 09:40

    You can use a middleware. Add this to your app.configure block:

    app.use(function (req, res, next) {
      req.root = 'WHAT YOU WANT';
      next();
    });
    

    Every request will go tough this function, and afterwards go to the right url-block thanks to next().

提交回复
热议问题