-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
49 lines (43 loc) · 1.26 KB
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Application } from "https://deno.land/x/abc/mod.ts";
/*
import { serve } from "https://deno.land/std/http/server.ts";
import { watch } from "https://deno.land/x/watch@1.1.0/mod.ts";
import {
acceptWebSocket,
isWebSocketCloseEvent,
isWebSocketPingEvent,
} from "https://deno.land/std/ws/mod.ts";
const port = Deno.args[0] || "8088";
*/
const app = new Application();
app.static("/", "./docs/").start({hostname: "0.0.0.0", port: 8080 });
/*
for await (const req of serve(`:${port}`)) {
const { conn, r: bufReader, w: bufWriter, headers } = req;
try {
const sock = await acceptWebSocket({
conn,
bufReader
bufWriter,
headers,
});
console.log("socket connected!");
try {
for await (const ev of sock) {
if (typeof ev === "string") {
console.log("ws:Text", ev);
await sock.send(ev);
} else if (isWebSocketPingEvent(ev)) {
const [,body] = ev;
console.log("ws:Ping", body);
} else if (isWebSocketCloseEvent(ev)) {
const { code, reason } = ev;
console.log("ws:Close", code, reason);
}
}
} catch (err) {
console.error(`failed to accept websocket: ${err}`);
await req.respond({ status: 400 });
}
}
*/