File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ FROM installer AS sources
1818COPY src /build/src
1919COPY examples /build/examples
2020COPY tsconfig.json /build/tsconfig.json
21+ COPY server.ts /build
2122
2223# Builder Image
2324FROM sources AS builder
Original file line number Diff line number Diff line change 66 "scripts" : {
77 "dev" : " bun --hot src/index.ts" ,
88 "start" : " bun src/index.ts" ,
9- "compile" : " bun build --compile --minify --sourcemap src/index .ts --outfile dist/openworkers-api" ,
9+ "compile" : " bun build --compile --minify --sourcemap server .ts --outfile dist/openworkers-api" ,
1010 "test" : " bun test"
1111 },
1212 "dependencies" : {
Original file line number Diff line number Diff line change 1+ /**
2+ * Production server entrypoint with graceful shutdown support
3+ *
4+ * This file is used for:
5+ * - Production runtime (bun server.ts)
6+ * - Compiled binary (bun run compile)
7+ *
8+ * It explicitly creates a Bun server to handle SIGTERM/SIGINT signals
9+ * for graceful shutdown (Docker, Ctrl+C, process managers).
10+ *
11+ * For development, use `bun --hot src/index.ts` which relies on
12+ * the default export and lets Bun handle hot reload lifecycle.
13+ */
14+ import app from "./src" ;
15+
16+ const server = Bun . serve ( app ) ;
17+
18+ process . on ( "SIGTERM" , ( ) => {
19+ console . log ( "SIGTERM received, shutting down gracefully..." ) ;
20+ server . stop ( true ) ;
21+ } ) ;
22+
23+ process . on ( "SIGINT" , ( ) => {
24+ console . log ( "SIGINT received, shutting down gracefully..." ) ;
25+ server . stop ( true ) ;
26+ } ) ;
Original file line number Diff line number Diff line change @@ -40,12 +40,13 @@ v1.route("/", users);
4040
4141app . route ( "/api/v1" , v1 ) ;
4242
43- import { port } from "./config" ;
43+ import { nodeEnv , port } from "./config" ;
4444
4545// Start server
4646console . log ( `OpenWorkers API starting on port ${ port } ...` ) ;
4747
4848export default {
4949 port,
5050 fetch : app . fetch ,
51+ development : nodeEnv === "development" ,
5152} ;
You can’t perform that action at this time.
0 commit comments