【问题标题】:How to CORS Allow Headers in Sails如何 CORS 允许 Sails 中的标头
【发布时间】:2015-10-08 11:40:48
【问题描述】:

我希望我的服务器允许我的移动应用使用“授权”标头。目前我的网络服务器在风帆中,我使用风帆。我的路线代码是

'post /auth/local' : {
    cors: {
       origin: '*'    
    },
    controller: 'AuthController',
    action: 'callback'
},

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

XMLHttpRequest cannot load http://localhost:1337/auth/local. 
Request header field Authorization is not allowed by Access-Control-Allow-Headers.

如何在我的路由代码中指定也允许“授权”标头?

【问题讨论】:

    标签: javascript express routes cors sails.js


    【解决方案1】:

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

    'post /auth/local' : {
        cors: {
           origin: '*',
           headers: 'Content-Type, Authorization'  
        },
        controller: 'AuthController',
        action: 'callback'
    },
    

    headers:允许与 CORS 请求一起发送的标头的逗号分隔列表。这仅用于回复preflight requests

    来源:Sails CORS Config

    请注意,Content-Type 也是必需的,因为它是该属性的默认值,并且是 POST 和 PUT 方法所必需的。

    【讨论】:

    • 我怎样才能一次完成所有路线?
    • 使用cors: trueconfig.cors.js,设置here.问候。
    猜你喜欢
    • 2017-05-26
    • 2022-06-25
    • 2013-05-05
    • 2015-09-01
    • 2017-04-16
    • 2018-01-23
    • 2018-07-06
    • 2021-11-10
    • 1970-01-01
    相关资源
    最近更新 更多