-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
48 lines (33 loc) · 931 Bytes
/
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
38
39
40
41
42
43
44
45
46
47
48
console.log("Compilation JS")
const runBuild = async () => {
console.log("compilation")
const result = await Bun.build({
entrypoints: ['./src/index.tsx'],
outdir: './build/',
})
console.log("compilation done")
if (!result.success) {
console.error("Build failed");
for (const message of result.logs) {
console.error(message);
}
}
}
const server = Bun.serve({
port: 3000,
async fetch(req) {
const url = new URL(req.url);
console.log("Request to:", url.pathname);
if (url.pathname === '/') {
return new Response(Bun.file("public/index.html"))
}
if (url.pathname === '/build/index.js') {
await runBuild();
return new Response(Bun.file('build/index.js'))
}
return new Response('page not found', {
status: 404
})
}
});
console.log(`Build sucessful, listening on http://localhost:${server.port}...`);