-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
server.ts
37 lines (32 loc) · 1.11 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
import { serve } from "https://deno.land/std@0.96.0/http/server.ts";
import { serveFile } from "https://deno.land/std@0.96.0/http/file_server.ts";
import { Sono } from "../../mod.ts"
const server = serve({ port: 8080 });
const sono = new Sono();
sono.channel('secret', ()=> {console.log('secret opened')})
for await (const req of server) {
if (req.method === "GET" && req.url === "/") {
const path = `${Deno.cwd()}/static/index.html`
const content = await serveFile(req, path);
req.respond(content)
}
else if (req.method === "GET" && req.url === "/ws") {
sono.connect(req, () => {
sono.emit('new client connected')
});
}
else if (req.method === "GET" && req.url === "/favicon.ico") {
// Do nothing in case of favicon request
continue;
}
else if (req.url === "/main.js") {
const path = `${Deno.cwd()}/static/main.js`
const content = await serveFile(req, path);
req.respond(content)
}
else if (req.method === "GET" && req.url === "/mod.ts"){
const path = `${Deno.cwd()}/../../mod.ts`;
const content = await serveFile(req, path);
req.respond(content)
}
}