31 lines
673 B
TypeScript
31 lines
673 B
TypeScript
import { buildApp } from "./app.js";
|
|
import { loadEnv } from "./config/env.js";
|
|
|
|
const env = loadEnv();
|
|
const app = await buildApp({ env });
|
|
|
|
const shutdown = async (signal: string) => {
|
|
app.log.info({ signal }, "Shutting down ProjectBrain API");
|
|
await app.close();
|
|
process.exit(0);
|
|
};
|
|
|
|
process.on("SIGINT", () => {
|
|
void shutdown("SIGINT");
|
|
});
|
|
|
|
process.on("SIGTERM", () => {
|
|
void shutdown("SIGTERM");
|
|
});
|
|
|
|
try {
|
|
await app.listen({ host: env.HOST, port: env.PORT });
|
|
app.log.info(
|
|
{ host: env.HOST, port: env.PORT },
|
|
"ProjectBrain API listening",
|
|
);
|
|
} catch (error) {
|
|
app.log.error(error, "ProjectBrain API failed to start");
|
|
process.exit(1);
|
|
}
|