Imagine you want to build a webpage health checker. I want users to send GET requests to https://localhost/check/{valid_url_here}
and I send a request to that URL. I couldn't find proper way of writing the correct router for this in Express.
This is the closest answer but it trims the url after ?
adding it to req.query
router.get('/check/:url*', (req, res) => {})
so when URL is https://example.com/?print=1
the variable req.params.url
misses the ?print
part... I want to capture anything that comes after /check/
CodePudding user response:
router.use("/check", function(req, res) {
var url = req.url.substring(1);
});
Then https://localhost/check/https://example.com/?print=1 leads to url = "https://example.com/?print=1"
.