Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove upgrade event from example #369

Closed
samlior opened this issue Jan 28, 2023 · 2 comments
Closed

Remove upgrade event from example #369

samlior opened this issue Jan 28, 2023 · 2 comments

Comments

@samlior
Copy link

samlior commented Jan 28, 2023

According to engine.io doc, it looks like the socket no longer emits the upgrade event, so it should be removed from this example.

By the way, I would like to ask how I should add some verification information in the upgrade request header, and reject the upgrade if the verification information is illegal.

@darrachequesne
Copy link
Member

Hi! The upgrade event was indeed missing from the documentation, this should be fixed now (socketio/engine.io@535b068).

how I should add some verification information in the upgrade request header, and reject the upgrade if the verification information is illegal.

You can manually handle the upgrade event of the Node.js HTTP server:

import { createServer } from "http";
import { Server } from "socket.io";

const httpServer = createServer();
const io = new Server(httpServer);

httpServer.removeAllListeners("upgrade");

httpServer.on("upgrade", (req, socket, head) => {
  // do some verification...

  // then
  io.engine.handleUpgrade(req, socket, head);
});

httpServer.listen(3000);

Reference: https://nodejs.org/api/http.html#event-upgrade_1

@samlior
Copy link
Author

samlior commented Feb 15, 2023

Thank you so much!

@samlior samlior closed this as completed Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants