Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

NodeJS - Disable JSONP on specific routes

NodeJS - Disable JSONP on specific routes

Problem

Solution

Looking at res.json(), it appears there's no explicit setting to disable JSONP per-route – it only checks the global app setting jsonp callback.

You could simply clear the value of req.query.callback before calling res.json() in any route you don't want to work via JSONP. As a middleware function:

function noJSONP(req, res, next) {
    delete req.query.callback;
    next();
}

Now you can just do this:

app.get('/something/sensitive', noJSONP, function(req, res) {
    // ...
});
Solution courtesy of: josh3736

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

NodeJS - Disable JSONP on specific routes

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×