0

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?

Zack Lee
  • 2,784
  • 6
  • 35
  • 77
  • Does this answer your question? [how to get request path with express req object](https://stackoverflow.com/questions/12525928/how-to-get-request-path-with-express-req-object) – tsamridh86 Nov 30 '20 at 03:25

1 Answers1

1

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);
});
Harshana
  • 5,151
  • 1
  • 17
  • 27