-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry.bun.ts
More file actions
59 lines (48 loc) · 1.55 KB
/
entry.bun.ts
File metadata and controls
59 lines (48 loc) · 1.55 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* WHAT IS THIS FILE?
*
* It's the entry point for the Bun HTTP server when building for production.
*
* Learn more about the Bun integration here:
* - https://qwik.dev/docs/deployments/bun/
* - https://bun.sh/docs/api/http
*
*/
import { createQwikCity } from "@builder.io/qwik-city/middleware/bun";
import qwikCityPlan from "@qwik-city-plan";
import { manifest } from "@qwik-client-manifest";
import render from "./entry.ssr";
// Create the Qwik City Bun middleware
const { router, notFound, staticFile } = createQwikCity({
render,
qwikCityPlan,
manifest,
});
const port = Number(Bun.env.PORT ?? 80);
// eslint-disable-next-line no-console
console.log(`Started at http://localhost:${port}/`);
const app = Bun.serve({
reusePort: true,
async fetch(request: Request) {
const url = new URL(request.url)
switch(url.pathname) {
case '/config/':
return new Response(Bun.file('./data/config.json'))
}
const staticResponse = await staticFile(request);
if (staticResponse) {
staticResponse.headers.set('Cache-Control', 'public, max-age=31536000, immutable')
return staticResponse
}
const qwikCityResponse = await router(request);
if (qwikCityResponse) return qwikCityResponse;
return notFound(request);
},
port
});
const shutdown = async () => {
await app.stop(true)
}
process.addListener('SIGKILL', shutdown);
process.addListener('SIGTERM', shutdown);
process.addListener('exit', shutdown);