2015-07-19 33 views
6

我希望我的服务器允许我的移动应用程序的'授权'标头。目前我的网络服务器在帆,我用帆。我的路线代码是如何在CORS允许航行标头

'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. 

是“授权”报头,也允许我怎么在我的路线代码中指定?

回答

11

headers : 'Content-Type, Authorization'添加到cors对象,如下面的例子:

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

头:被允许与CORS请求被发送报头的逗号分隔的列表。这仅用于响应preflight requests

来源:Sails CORS Config

注意Content-Type也需要因是该属性的默认值,需要POST和PUT方法。

+0

我该如何对所有路线一次做到这一点? – raju

+0

使用'cors:true'和[config.cors.js](http://sailsjs.org/documentation/reference/configuration/sails-config-cors),setup [here](http://sailsjs.org/文档/概念/安全/ CORS).Regards。 –

相关问题