-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathserver.ts
More file actions
42 lines (36 loc) · 1.11 KB
/
server.ts
File metadata and controls
42 lines (36 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import './src/utils/cjs-polyfill';
import './src/utils/instrumentation';
import {fileURLToPath} from 'url';
const isMainModule = process.argv[1] === fileURLToPath(import.meta.url);
const port: number = parseInt(process.env.PORT || '3000', 10);
const listenHost: string = process.env.LISTEN_HOST || '0.0.0.0';
const isWorkerMode = process.env.WORKER_MODE === 'true';
import workerApp from './src/worker-app';
import mainApp from './src/app';
// Load the appropriate app once
let app;
if (isWorkerMode) {
app = workerApp;
} else {
app = mainApp;
}
// Start the server if this file is run directly
if (isMainModule) {
const start = async (): Promise<void> => {
try {
await app.listen({host: listenHost, port});
} catch (err) {
// Use app.log if available, otherwise fallback to console
if (app && app.log) {
app.log.error(err);
} else {
// eslint-disable-next-line no-console
console.error(err);
}
process.exit(1);
}
};
start();
}
// Export the app
export default app;