How to use with oak? #9
-
Is it possible to use it with https://github.com/oakserver/oak? |
Beta Was this translation helpful? Give feedback.
Answered by
darrachequesne
Nov 29, 2022
Replies: 1 comment 3 replies
-
Hi! You need to use the .handle() method: import { serve } from "https://deno.land/[email protected]/http/server.ts";
import { Server } from "https://deno.land/x/[email protected]/mod.ts";
import { Application } from "https://deno.land/x/[email protected]/mod.ts";
const app = new Application();
app.use((ctx) => {
ctx.response.body = "Hello World!";
});
const io = new Server();
io.on("connection", (socket) => {
console.log(`socket ${socket.id} connected`);
socket.emit("hello", "world");
socket.on("disconnect", (reason) => {
console.log(`socket ${socket.id} disconnected due to ${reason}`);
});
});
const handler = io.handler(async (req) => {
return await app.handle(req) || new Response(null, { status: 404 });
});
await serve(handler, {
port: 3000,
}); Added in the documentation here: https://github.com/socketio/socket.io-deno#with-oak |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
darrachequesne
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! You need to use the .handle() method: