SheldonFromBBT
SheldonFromBBT10mo ago

The new and updated version for using socket.io handler with Deno.serve()

Hey there! am getting a error when I pass socket.io handler to Deno.serve(), Here is what am doing : Deno.serve(io.handler(), { port: 3000, }); Additional code for refrence : import { Server } from "https://deno.land/x/socket_io@0.2.0/mod.ts"; const io = new Server({ cors: { origin: [ "https://localhost:5173", ], credentials: true, methods: ["GET", "POST"], }, });
6 Replies
SheldonFromBBT
SheldonFromBBTOP10mo ago
It works with old deprecated serve() method What's the solution here ? Thanks! I was following the guide on socket.io docs but it's outdated to current standards
Leokuma
Leokuma10mo ago
See this for a workaround while the module is not updated: https://github.com/socketio/socket.io-deno/issues/17#issuecomment-1952487057
GitHub
std/http/server.ts>serve is deprecated, io.handler() is incompatibl...
Describe the bug Deno's std/http/server.ts>serve is deprecated and will be removed in version 1.0.0. Instead they suggest to use Deno.serve. This library currently does not seem to be compat...
SheldonFromBBT
SheldonFromBBTOP10mo ago
This doesn't seem to work What should be the values for hostname and port here?
Leokuma
Leokuma10mo ago
IDK, sorry. But you can ask in that issue. You have a better chance asking there than here
Fifth-Normal-Form always
The order of args has changed:
// change this:
Deno.serve(customIOHandler, {port: 3000});
// to this
Deno.serve({port: 3000}, customIOHandler)
// change this:
Deno.serve(customIOHandler, {port: 3000});
// to this
Deno.serve({port: 3000}, customIOHandler)
The options now come first, then the callback function.
Also: The port and hostname options are optional. If not supplied, they default to 8080 and "localhost".
If these defaults are ok, then just use:
Deno.serve(customIOHandler);
Deno.serve(customIOHandler);
SheldonFromBBT
SheldonFromBBTOP10mo ago
Still I can't make it work IDK where am i going wrong I did all the steps as you mentioned But my client socket don't seem to connect to the server Old way was working all fine and good What are the security issues and overall downsides of using the connection old way (with serve() method)? Untill we have a official update and upgrade Well thanks I got it working! I had to use transports: ["websocket"] during client initialising