-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.ts
More file actions
43 lines (37 loc) · 1.16 KB
/
server.ts
File metadata and controls
43 lines (37 loc) · 1.16 KB
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
import { Application, join, send } from "./deps.ts";
const port: any = Deno.env.get("PORT") || 3000;
const hostname = "0.0.0.0";
const server: Application = new Application();
server.use(async (ctx, next) => {
const filePath = ctx.request.url.pathname;
if (filePath.slice(0, 7) === "/assets") {
await send(ctx, filePath, {
root: join(Deno.cwd(), "src"),
});
} else if (filePath === "/") {
await send(ctx, filePath, {
root: join(Deno.cwd(), "public"),
index: "index.html",
});
} else if (filePath === "/build.js") {
ctx.response.type = "application/javascript";
await send(ctx, filePath, {
root: join(Deno.cwd(), "vno-build"),
index: "build.js",
});
} else if (filePath === "/style.css") {
ctx.response.type = "text/css";
await send(ctx, filePath, {
root: join(Deno.cwd(), "vno-build"),
index: "style.css",
});
} else await next();
});
server.addEventListener("error", (err) => console.warn(err));
server.addEventListener("listen", () => {
console.log(`server is listening on ${hostname}:${port}`);
});
if (import.meta.main) {
await server.listen({ port, hostname });
}
export { server };