簡體   English   中英

如何在Sails.js API上正確配置CORS

[英]How to configure properly CORS on sailsjs api

我的應用程序由前端的angularjs和后端的sailsjs組成。 我正在嘗試在后端配置CORS,但是沒有成功。 我希望只能從地址blog.example.com的前端訪問地址api.example.com上的后端。 我對sails config / cors.js的設置是:

allRoutes: false,
origin: 'http://blog.example.com',
credentials: true,
methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
headers: 'content-type'

結果是,如果我在瀏覽器地址欄中輸入api.example.com,則可以自由訪問我的后端,但不能從前端訪問它! 在Chrome中,我得到答案:“'Access-Control-Allow-Origin'標頭包含無效值''”,Firefox僅發送空的響應正文。 我也嘗試在config / routes.js中配置cors,但是也沒有成功。 任何幫助表示贊賞!

您需要allRoutes: true除非您逐條路由啟用cors。

http://sailsjs.org/documentation/concepts/security/cors

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM