-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.ts
63 lines (53 loc) · 1.5 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) justjavac. All rights reserved. MIT License.
import { serve } from "https://deno.land/std@0.152.0/http/server.ts";
import { bundle } from "https://deno.land/x/emit@0.4.0/mod.ts";
async function handleRequest(request: Request) {
const { pathname } = new URL(request.url);
if (pathname.startsWith("/favicon.ico")) {
return new Response(await Deno.readFile("assets/favicon.ico"), {
headers: {
"content-type": "image/x-icon",
},
});
}
if (pathname.endsWith(".css")) {
const file = await Deno.readFile(pathname.substring(1));
return new Response(file, {
headers: {
"content-type": "text/css",
},
});
}
if (pathname.endsWith(".png")) {
const file = await Deno.readFile(pathname.substring(1));
return new Response(file, {
headers: {
"content-type": "image/png",
},
});
}
if (pathname.endsWith(".mpeg")) {
const file = await Deno.readFile(pathname.substring(1));
return new Response(file, {
headers: {
"content-type": "video/mpeg",
},
});
}
if (pathname.startsWith("/bundled.js")) {
const { code } = await bundle(new URL("./src/entry.ts", import.meta.url), {
cacheRoot: "./cache",
});
return new Response(code, {
headers: {
"content-type": "text/javascript",
},
});
}
return new Response(await Deno.readFile("index.html"), {
headers: {
"content-type": "text/html; charset=utf-8",
},
});
}
serve(handleRequest);