expressjs: get requested url

后端 未结 4 1917
情深已故
情深已故 2021-02-19 07:02

I want to get the url the client has requested out of the request.

Currently I use:

var requestedUrl = req.protocol + \'://\' + req.host + \':3000\' + re         


        
4条回答
  •  天涯浪人
    2021-02-19 07:30

    I often times add something like this to my express app:

      app.use(function(req, res, next) {
        req.getRoot = function() {
          return req.protocol + "://" + req.get('host');
        }
        return next();
      });
    

    Now you have a function you can call on demand if you need it.

提交回复
热议问题