@bractjs/bractjs 0.1.18 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/server/serve.ts +21 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bractjs/bractjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "Production-grade SSR framework for Bun + React 19. File-based routing, streaming SSR, server actions, typed routes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/bractjs/bractjs#readme",
|
package/src/server/serve.ts
CHANGED
|
@@ -183,6 +183,7 @@ async function warnIfStaleBuild(buildDir: string): Promise<void> {
|
|
|
183
183
|
// HMR restarts and multiple createServer() calls in the same process.
|
|
184
184
|
let signalsRegistered = false;
|
|
185
185
|
let isShuttingDown = false;
|
|
186
|
+
let activeOnShutdown: (() => Promise<void> | void) | undefined;
|
|
186
187
|
|
|
187
188
|
export function createServer(config?: Partial<BractJSConfig>): {
|
|
188
189
|
stop(): void;
|
|
@@ -209,6 +210,8 @@ export function createServer(config?: Partial<BractJSConfig>): {
|
|
|
209
210
|
adapter.listen?.(port);
|
|
210
211
|
}
|
|
211
212
|
|
|
213
|
+
activeOnShutdown = config?.onShutdown;
|
|
214
|
+
|
|
212
215
|
console.log(`[bract] Server running at http://localhost:${port}`);
|
|
213
216
|
|
|
214
217
|
const stopAdapter = () => {
|
|
@@ -219,28 +222,37 @@ export function createServer(config?: Partial<BractJSConfig>): {
|
|
|
219
222
|
}
|
|
220
223
|
};
|
|
221
224
|
|
|
222
|
-
const gracefulShutdown =
|
|
225
|
+
const gracefulShutdown = (signal?: string) => {
|
|
223
226
|
if (isShuttingDown) return;
|
|
224
227
|
isShuttingDown = true;
|
|
225
228
|
if (signal) console.log(`\n[bract] Received ${signal}, shutting down…`);
|
|
226
229
|
try {
|
|
227
|
-
|
|
230
|
+
const result = activeOnShutdown?.();
|
|
231
|
+
if (result instanceof Promise) {
|
|
232
|
+
result.catch((err) => console.error("[bract] onShutdown error:", err)).finally(() => {
|
|
233
|
+
stopAdapter();
|
|
234
|
+
process.exit(0);
|
|
235
|
+
});
|
|
236
|
+
} else {
|
|
237
|
+
stopAdapter();
|
|
238
|
+
process.exit(0);
|
|
239
|
+
}
|
|
228
240
|
} catch (err) {
|
|
229
241
|
console.error("[bract] onShutdown error:", err);
|
|
242
|
+
stopAdapter();
|
|
243
|
+
process.exit(1);
|
|
230
244
|
}
|
|
231
|
-
stopAdapter();
|
|
232
|
-
process.exit(0);
|
|
233
245
|
};
|
|
234
246
|
|
|
235
247
|
if (!signalsRegistered) {
|
|
236
248
|
signalsRegistered = true;
|
|
237
|
-
process.on("SIGTERM", () =>
|
|
238
|
-
process.on("SIGINT", () =>
|
|
239
|
-
process.on("SIGUSR2", () =>
|
|
240
|
-
process.on("beforeExit", () =>
|
|
249
|
+
process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
|
|
250
|
+
process.on("SIGINT", () => gracefulShutdown("SIGINT"));
|
|
251
|
+
process.on("SIGUSR2", () => gracefulShutdown("SIGUSR2"));
|
|
252
|
+
process.on("beforeExit", () => gracefulShutdown());
|
|
241
253
|
process.on("uncaughtException", (err) => {
|
|
242
254
|
console.error("[bract] Uncaught exception:", err);
|
|
243
|
-
|
|
255
|
+
gracefulShutdown("uncaughtException");
|
|
244
256
|
});
|
|
245
257
|
}
|
|
246
258
|
|