Node.js loopback4中的Socket.io

Node.js loopback4中的Socket.io,node.js,socket.io,loopback4,Node.js,Socket.io,Loopback4,我想在环回4中实现套接字,我无法从前端连接到已建立的连接 var serverStartedTime = (new Date).getTime(); const io = require('socket.io')(await app.start()); io.on('connection', (socket: any) => { console.log("Socket Connection estiblished") app.io.emit('chat mess

我想在环回4中实现套接字,我无法从前端连接到已建立的连接

  var serverStartedTime = (new Date).getTime();
  const io = require('socket.io')(await app.start());
  io.on('connection', (socket: any) => {
    console.log("Socket Connection estiblished")
    app.io.emit('chat message', {startTime: serverStartedTime});
  })
请任何人都能在这方面帮助我

如果你尝试一下这个怎么办:

const http = require("http");
const server = http.createServer(app);
const io = require("socket.io").listen(server);

使用请求模块。它忽略了cors

或者使用原始插座

您还可以使用,您可能需要添加标题

Request-With: XmlHttpRequest

这个代码在application.ts上吗?你的问题似乎不完整。简要回答你的问题。这是我在index.ts文件中编写的代码,与application.ts@MadakyI并行。我在这里得到了CROS错误,你得到了cors错误。那你为什么不允许在io上使用cors呢?这真的值得赏金吗?来吧,伙计,Cross在我实现的所有其他api中都工作得很好