2015-07-19 61 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。 –

相關問題