30 lines
726 B
JavaScript
30 lines
726 B
JavaScript
import './config/env.js';
|
|
import { startApi, stopApi } from './api/index.js';
|
|
import { closeStore } from './db/store.js';
|
|
import { createLogger } from './util/logger.js';
|
|
|
|
const sysLog = createLogger('system');
|
|
|
|
async function shutdown() {
|
|
await stopApi();
|
|
try {
|
|
await closeStore();
|
|
} catch (error) {
|
|
sysLog.error('Failed to close database:', error);
|
|
process.exitCode = 1;
|
|
}
|
|
}
|
|
|
|
process.on('SIGINT', () => {
|
|
shutdown().then(() => process.exit(0));
|
|
});
|
|
process.on('SIGTERM', () => {
|
|
shutdown().then(() => process.exit(0));
|
|
});
|
|
|
|
// MARK: calls startApi from ./api/index.js
|
|
startApi().catch((err) => {
|
|
sysLog.error('Failed to start API:', err.message);
|
|
process.exit(1);
|
|
});
|