-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
36 lines (33 loc) · 934 Bytes
/
index.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
import { compile } from "./build-html.ts";
import cv from "./cv.json";
import template from "./theme/template.txt";
import { withHtmlLiveReload } from "bun-html-live-reload";
if (import.meta.main) {
Bun.serve(
withHtmlLiveReload({
port: 3000,
async fetch(req) {
if (req.url.endsWith("/")) {
const html = compile(template, cv);
return new Response(html, {
headers: {
"Content-Type": "text/html",
},
});
} else if (req.url.endsWith(".css")) {
const path = req.url.split("/").pop();
return new Response(Bun.file(`theme/${path}`), {
headers: {
"Content-Type": "text/css",
},
});
} else {
return new Response("Not found", {
status: 404,
});
}
},
})
);
console.log(`Serving at http://localhost:3000/`);
}