我有我的快遞服務器上http://localhost:3000運行(我稱之爲web服務器) 我有另一個應用程序在本地主機上運行:8100(我把這個簡單的「應用」)獲取Express服務器接受CORS請求
當我的應用程序打電話給Web服務器我收到消息:
"XMLHTTPReqeust cannot load http://localhost:3000/auth/facebook. Response to preflight request doesn't pass access control check. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' when the credentials flag is true. Origin 'http://localhost:81000' is therefore not allowed acecss"
此消息顯示在瀏覽器控制檯中。
我已經安裝在我的節點的網絡服務器
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT, POST,DELETE');
的中間件下列選項讀幾stackoverfow問題後,我還增加了以下內容:
res.header('Access-Control-Allow-Origin', 'http://localhost:8100');
然而,這並不解決問題。
您還需要在'Access-Control-Allow-Methods'中允許'OPTIONS'方法 –