【发布时间】:2016-09-07 18:31:40
【问题描述】:
我正在尝试从我的 express、nodejs 应用程序返回 jsonp,并且我不断获取 text/javascript 而不是 application/javascript(我认为应该是正确的 Content-Type)。 IE
// Method 1
res.setHeader('Content-Type', 'application/javascript');
res.status(200).jsonp(result);
// Method 2
res.format({
'application/javascript': function() {
res.status(200).jsonp(result);
}
});
// Method 3
res.set('Content-Type', 'application/javascript');
res.status(200).jsonp(result);
但无论如何,我得到的 Content-Type 始终是 text/javascript,如下所示。我还在响应标头中获得了两次“nosniff”标头:-/ 我在已彻底检查过的 nginx.conf 文件中只有一次。甚至做了一个 nginx -t ,它说配置很好。
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 12 May 2016 05:06:28 GMT
Content-Type: text/javascript; charset=utf-8
Content-Length: 433
Connection: keep-alive
Keep-Alive: timeout=5
X-Powered-By: Express
Vary: Accept
X-Content-Type-Options: nosniff
ETag: W/"1b1-1ZnUnapTaayP/+6QW4iqXQ"
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Strict-Transport-Security: max-age=315360000; includeSubdomains
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Robots-Tag: none
我使用 nginx 作为反向代理,使用“上游事物”。我也在我的应用程序中使用 bodyParser。如果需要任何进一步的信息,请告诉我,因为我对 node/express 完全陌生。谢谢
【问题讨论】:
标签: javascript node.js express nginx content-type