diff --git a/README.md b/README.md index f0da9c9..d102b5f 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,8 @@ const io = new Server< ### With oak -You need to use the [.handle()](https://github.com/oakserver/oak#handle-method) method: +You need to use the [.handle()](https://github.com/oakserver/oak#handle-method) +method: ```ts import { serve } from "https://deno.land/std@0.166.0/http/server.ts"; @@ -92,32 +93,27 @@ import { Application } from "https://deno.land/x/oak@v11.1.0/mod.ts"; const app = new Application(); app.use((ctx) => { - ctx.response.body = "Hello World!"; + ctx.response.body = "Hello World!"; }); const io = new Server(); io.on("connection", (socket) => { - console.log(`socket ${socket.id} connected`); + console.log(`socket ${socket.id} connected`); - socket.emit("hello", "world"); + socket.emit("hello", "world"); - socket.on("disconnect", (reason) => { - console.log(`socket ${socket.id} disconnected due to ${reason}`); - }); + socket.on("disconnect", (reason) => { + console.log(`socket ${socket.id} disconnected due to ${reason}`); + }); }); const handler = io.handler(async (req) => { - const response = await app.handle(req); - if (response) { - return response; - } else { - return new Response(null, { status: 404 }); - } + return await app.handle(req) || new Response(null, { status: 404 }); }); await serve(handler, { - port: 3000, + port: 3000, }); ```