-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ts
37 lines (32 loc) · 1.17 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
import { $ } from "bun"
import {
isDev,
createServer,
files,
dir,
route,
} from "./www"
import index from "./index"
import poop from "./poop"
import days from "./days"
import resume from "./resume"
import jap from "./jap"
// TODO: live reload
if (isDev) {
await $`make fonts`
}
const server = createServer()
console.log(`server starting at ${server.url.toString()}`)
const linksText = await Bun.file("files/links.txt").text()
const links = linksText.split("\n").filter((l) => l)
const rand = (a: number, b: number) => Math.floor(a + Math.random() * (b - a))
const randItem = <D>(arr: D[]) => arr[rand(0, arr.length)]
server.use(files("/static", "static"))
server.use(dir("/files", "files"))
server.use(route("GET", "/", ({ res }) => res.sendHTML(index)))
server.use(route("GET", "/poop", ({ res }) => res.sendHTML(poop)))
server.use(route("GET", "/days", ({ res }) => res.sendHTML(days)))
server.use(route("GET", "/resume", ({ res }) => res.sendHTML(resume)))
server.use(route("GET", "/portfolio", ({ res }) => res.sendHTML(resume)))
server.use(route("GET", "/jap", ({ res }) => res.sendHTML(jap)))
server.use(route("GET", "/randomlink", ({ res }) => res.redirect(randItem(links), 303)))