Reputation: 1110
I have the following route in my Express project:
router.get('/statusCode/:url', function(req, res){
//finds the http status code of a webpage
try {
req.param.url = utils.formatUrl(req.param.url);
} catch (err) {
res.render('siteError', {error: "Invalid url"});
}
utils.getStatusCode(req.params.url)
.then(function(statusCode){
req.statusCode = statusCode;
renderPage(req, res);
}).catch(function(err){
utils.errorHandler(err);
});
});
I want to be able to do localhost:3000/statusCode/http://www.google.com
, but the route never gets called on the server. How can I map urls to go to this route?
Upvotes: 3
Views: 1008
Reputation: 6507
You need to use encodeURI()
to encode URI string that you want to pass on. Then you can decodeURI()
on the server side and redirect the user to it.
Upvotes: 2