我的節點后端設定在 Heroku 上,React 前端設定在 Netlify 上。在 Firefox 上一切正常,但在 chrome 上我可以登錄(發布請求),然后我無法在我的頁面上移動,因為 cors 策略阻止了我對服務器的獲取請求。
從源“https://xxx.netlify.app”訪問“https://xxx.herokuapp.com/api/fetchPurchasedPrizes”的 XMLHttpRequest 已被 CORS 策略阻止:沒有“Access-Control-Allow-Origin”標頭存在于請求的資源上。
我的后端 cors 設定
app.use(
cors({
credentials: true,
origin: 'xxx.netlify.app',
}),
);
在 localhost 上,兩個瀏覽器都運行良好。
uj5u.com熱心網友回復:
簡單的解決方案,我只需要添加
cookie: {
sameSite: 'none',
secure: 'true',
},
到我的會話配置。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/405808.html
標籤:
