Skip to content

Commit

Permalink
feat(cli): update index template
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Nov 27, 2024
1 parent 92336fd commit 5ebc03a
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions packages/cli/templates/init/src/index.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@ import {$log} from "@tsed/logger";
import { {{platformSymbol}} } from "@tsed/platform-{{platform}}";
import {Server} from "./{{entryServer}}.js";

async function bootstrap() {
try {
const platform = await {{platformSymbol}}.bootstrap(Server);
await platform.listen();
const SIG_EVENTS = [
"beforeExit",
"SIGHUP",
"SIGINT",
"SIGQUIT",
"SIGILL",
"SIGTRAP",
"SIGABRT",
"SIGBUS",
"SIGFPE",
"SIGUSR1",
"SIGSEGV",
"SIGUSR2",
"SIGTERM"
];

process.on("SIGINT", () => {
platform.stop();
});
} catch (error) {
$log.error({event: "SERVER_BOOTSTRAP_ERROR", message: error.message, stack: error.stack});
}
try {
const platform = await {{platformSymbol}}.bootstrap(Server);
await platform.listen();

SIG_EVENTS.forEach((evt) => process.on(evt, close));

["uncaughtException", "unhandledRejection"].forEach((evt) =>
process.on(evt, async (error) => {
$log.error({event: "SERVER_" + evt.toUpperCase(), message: error.message, stack: error.stack});
await stop();
})
);
} catch (error) {
$log.error({event: "SERVER_BOOTSTRAP_ERROR", message: error.message, stack: error.stack});
}

bootstrap();

0 comments on commit 5ebc03a

Please sign in to comment.