简体   繁体   中英

How to get appended URL value? (e.g. localhost:3000/URL)

I'm trying to use other URL to be used as a data in my app.

For example, If I visit localhost:3000/https://www.google.com/robots.txt

Then I would like to get https://www.google.com/robots.txt as a parameter so I can use it.

I tried the following approach but it only works if the trailing value has no slash.

app.get('/:id', function (req, res) {
  res.send(req.params)
})

Is there a possible way to get the appended URL?

You can use /* to grab the Parameters and then get the index 0 to get the exact URL

app.get('/*', function(req, res) {
  var url = req.params[0];
  res.send(url);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM