Sunday, 12 March 2017

Using a url as a slug in Express

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?



via db2791

No comments:

Post a Comment