如何CORS允许在风帆中的标题

raj*_*aju 9 javascript routes cors express sails.js

我希望我的服务器允许我的移动应用程序的"授权"标题.目前我的网络服务器是帆,我使用帆.我的路线代码是

'post /auth/local' : {
    cors: {
       origin: '*'    
    },
    controller: 'AuthController',
    action: 'callback'
},
Run Code Online (Sandbox Code Playgroud)

当我的客户端在标头中发送带有"授权"的请求时,我收到错误

XMLHttpRequest cannot load http://localhost:1337/auth/local. 
Request header field Authorization is not allowed by Access-Control-Allow-Headers.
Run Code Online (Sandbox Code Playgroud)

如何在我的路线代码中指定还允许"授权"标题?

rnr*_*ies 15

添加headers : 'Content-Type, Authorization'cors对象,如下例所示:

'post /auth/local' : {
    cors: {
       origin: '*',
       headers: 'Content-Type, Authorization'  
    },
    controller: 'AuthController',
    action: 'callback'
},
Run Code Online (Sandbox Code Playgroud)

headers:允许与CORS请求一起发送的以逗号分隔的标头列表.这仅用于响应预检请求.

来源:Sails CORS配置

请注意,Content-Type还需要该属性的默认值,并且是POST和PUT方法所必需的.