Skip to content

io.engine undefined? #5376

Discussion options

You must be logged in to vote

It's possible, but a bit more verbose:

import { createServer } from "node:http";
import { Server } from "socket.io";
import { Server as Engine } from "engine.io";

const httpServer = createServer();

const io = new Server();
const engine = new Engine();
io.bind(engine);

const io2 = new Server();
const engine2 = new Engine();
io2.bind(engine2);

httpServer.on("request", (req, res) => {
  if (res.writableEnded) {
    return; // already handled, nothing to do
  } else if (req.url.startsWith("/first/")) {
    engine.handleRequest(req, res);
  } else if (req.url.startsWith("/second/")) {
    engine2.handleRequest(req, res);
  } else {
    res.writeHead(404);
    res.end();
  }
});

httpServer.on

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@SupertigerDev
Comment options

@darrachequesne
Comment options

Answer selected by SupertigerDev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants