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);
});
Thank you that works perfectly! Do you know if it's possible to send index.html with that parameter?
You can follow this guide to do that : codeforgeek.com/render-html-file-expressjs