如何在 Sails 中实现 CORS 允许 Headers
How to CORS Allow Headers in Sails
我希望我的服务器允许 'Authorization' header 用于我的移动应用程序。目前我的网络服务器在风帆中,我使用风帆。我的路线代码是
'post /auth/local' : {
cors: {
origin: '*'
},
controller: 'AuthController',
action: 'callback'
},
当我的客户在 header 中发送带有 'Authorization' 的请求时,我收到错误消息
XMLHttpRequest cannot load http://localhost:1337/auth/local.
Request header field Authorization is not allowed by Access-Control-Allow-Headers.
如何在我的路线代码中指定 'Authorization' header 也被允许?
将 headers : 'Content-Type, Authorization'
添加到 cors
对象,如下例所示:
'post /auth/local' : {
cors: {
origin: '*',
headers: 'Content-Type, Authorization'
},
controller: 'AuthController',
action: 'callback'
},
headers: Comma-delimited list of headers that are allowed to be sent with CORS requests. This is only used in response to preflight requests.
请注意,Content-Type
也是必需的,因为 属性 的默认值是 POST 和 PUT 方法所必需的。
我希望我的服务器允许 'Authorization' header 用于我的移动应用程序。目前我的网络服务器在风帆中,我使用风帆。我的路线代码是
'post /auth/local' : {
cors: {
origin: '*'
},
controller: 'AuthController',
action: 'callback'
},
当我的客户在 header 中发送带有 'Authorization' 的请求时,我收到错误消息
XMLHttpRequest cannot load http://localhost:1337/auth/local.
Request header field Authorization is not allowed by Access-Control-Allow-Headers.
如何在我的路线代码中指定 'Authorization' header 也被允许?
将 headers : 'Content-Type, Authorization'
添加到 cors
对象,如下例所示:
'post /auth/local' : {
cors: {
origin: '*',
headers: 'Content-Type, Authorization'
},
controller: 'AuthController',
action: 'callback'
},
headers: Comma-delimited list of headers that are allowed to be sent with CORS requests. This is only used in response to preflight requests.
请注意,Content-Type
也是必需的,因为 属性 的默认值是 POST 和 PUT 方法所必需的。