节点,尽管设置了application/javascript,express app仍返回text/javascript响应标头(Content-Type) [英] node, express app returns text/javascript response header (Content-Type) in spite of setting application/javascript

查看:409
本文介绍了节点,尽管设置了application/javascript,express app仍返回text/javascript响应标头(Content-Type)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的express,nodejs应用程序返回jsonp,并且我一直在获取text/javascript而不是application/javascript(我认为这应该是正确的Content-Type).我对IE< 8.返回结果时,我尝试设置内容类型的各种方式如下所示:

I am trying to return jsonp from my express, nodejs application and I keep getting text/javascript instead of application/javascript (which I think should be the correct Content-Type). I am not bothered about IE < 8. The various ways that I have tried to set the content-type when returning the result is shown below:

// 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并说config很好.

But no matter what, the Content-Type that I get is always text/javascript as shown below. I also get 'nosniff' header twice in the response headers :-/ I have it only once in my nginx.conf file which I have thoroughly checked. Even did a nginx -t and it says config is fine.

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的新手.谢谢

I am using nginx as a reverse proxy using the 'upstream thingy'. I am also using bodyParser in my application. Please let me know if any further information is needed as I am absolutely new to node/express. Thanks

推荐答案

恐怕内容类型在Express中是硬编码的.参见此处.

I'm afraid that the content type is hard coded in Express. See here.

从外观上看,唯一的办法是自己重新实现.jsonp()(或在GitHub上为Express开发人员创建一个问题来修复它).

By the looks of it, the only way around that is to re-implement .jsonp() yourself (or create an issue on GitHub for the Express devs to fix it).

这篇关于节点,尽管设置了application/javascript,express app仍返回text/javascript响应标头(Content-Type)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆