Skip to content

Commit 7f47539

Browse files
docs: add example with oak (2)
1 parent ae9f331 commit 7f47539

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

README.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ const io = new Server<
8282

8383
### With oak
8484

85-
You need to use the [.handle()](https://github.com/oakserver/oak#handle-method) method:
85+
You need to use the [.handle()](https://github.com/oakserver/oak#handle-method)
86+
method:
8687

8788
```ts
8889
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";
9293
const app = new Application();
9394

9495
app.use((ctx) => {
95-
ctx.response.body = "Hello World!";
96+
ctx.response.body = "Hello World!";
9697
});
9798

9899
const io = new Server();
99100

100101
io.on("connection", (socket) => {
101-
console.log(`socket ${socket.id} connected`);
102+
console.log(`socket ${socket.id} connected`);
102103

103-
socket.emit("hello", "world");
104+
socket.emit("hello", "world");
104105

105-
socket.on("disconnect", (reason) => {
106-
console.log(`socket ${socket.id} disconnected due to ${reason}`);
107-
});
106+
socket.on("disconnect", (reason) => {
107+
console.log(`socket ${socket.id} disconnected due to ${reason}`);
108+
});
108109
});
109110

110111
const handler = io.handler(async (req) => {
111-
const response = await app.handle(req);
112-
if (response) {
113-
return response;
114-
} else {
115-
return new Response(null, { status: 404 });
116-
}
112+
return await app.handle(req) || new Response(null, { status: 404 });
117113
});
118114

119115
await serve(handler, {
120-
port: 3000,
116+
port: 3000,
121117
});
122118
```
123119

0 commit comments

Comments
 (0)