Failed to load http://localhost:3000/products: The 'Access-Control-Allow-Origin' header has a value

用node寫了個接口,但是啓動前端的時候一直請求不到數據,報錯

Failed to load http://localhost:3000/products: The ‘Access-Control-Allow-Origin’ header has a value ‘http://127.0.0.1:3000’ that is not equal to the supplied origin.

後來在node後端設置了一個請求頭,也就是serve.on()里加了一行代碼,設置一個請求頭,問題就解決了。
不是剛開始想的跨域問題

res.setHeader("Access-Control-Allow-Origin", "*");
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章