[英]Getting CORS EROOR on socket.io and express(node.js)
Socket.io 和 Node.js (express.js) 得到 CORS 錯誤
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.