NodeJS-禁用特定路由上的JSONP

NodeJS - Disable JSONP on specific routes

本文关键字:JSONP 路由 NodeJS-      更新时间:2023-12-18

我正在使用Express。如何禁用特定路由的JSONP

查看res.json(),似乎没有明确设置禁用每条路由的JSONP–它只检查全局应用程序设置CCD_ 3。

在任何不想通过JSONP工作的路由中调用res.json()之前,您可以简单地清除req.query.callback的值。作为中间件功能:

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

现在你可以这样做:

app.get('/something/sensitive', noJSONP, function(req, res) {
    // ...
});