[英]Socket.io + Node.js CORS ERROR Blocked my req
我正在使用 node 和 socket.io 編寫一個應用程序,它給出了啟用跨源請求的錯誤。
const io = require("./socket").init(server, {
cors: {
origin: "*",
methods: ["GET", "POST"],
},
});
這是我的 soket.io 代碼...
let io;
module.exports = {
init: (httpServer) => {
io = require("socket.io")(httpServer);
return io;
},
getIO: () => {
if (!io) {
throw new Error("Socket.io not inittialized");
}
return io;
},
};
提前幫我解決這個問題......
在必須發送的套接字 js 中嘗試此代碼
cors: {
origin: "*",
methods: ["GET", "POST"],
},
套接字中的Cors也避免了這個錯誤
let io;
module.exports = {
init: (httpServer) => {
io = require("socket.io")(httpServer, {
cors: {
origin: "*",
methods: ["GET", "POST"],
},
});
return io;
},
getIO: () => {
if (!io) {
throw new Error("Socket.io not inittialized");
}
return io;
},
};
希望對你有幫助...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.