Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7f47539

Browse files
docs: add example with oak (2)
1 parentae9f331 commit7f47539

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=newApplication();
9394

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

9899
const io=newServer();
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=awaitapp.handle(req);
112-
if (response) {
113-
returnresponse;
114-
}else {
115-
returnnewResponse(null, { status:404 });
116-
}
112+
returnawaitapp.handle(req)||newResponse(null, { status:404 });
117113
});
118114

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp