forked from jagregory/cognito-local
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.ts
44 lines (37 loc) · 1.17 KB
/
start.ts
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
43
44
#!/usr/bin/env node
import process from 'node:process';
import { pino } from 'pino';
import PinoPretty from 'pino-pretty';
import { createDefaultServer } from '../server/index.js';
const logger = pino(
{
level: process.env.DEBUG ? 'debug' : 'info',
},
PinoPretty({
colorize: true,
ignore: 'pid,name,hostname',
singleLine: true,
messageFormat: (log, messageKey) =>
`${(log['reqId'] as string) ?? 'NONE'} ${(log['target'] as string) ?? 'NONE'} ${log[messageKey] as string}`,
})
);
createDefaultServer(logger)
.then((server) => {
const hostname = process.env.HOST ?? 'localhost';
const port = parseInt(process.env.PORT ?? '9229', 10);
return server.start({ hostname, port });
})
.then((httpServer) => {
const address = httpServer.address();
if (!address) {
throw new Error('Server started without address');
}
const url = typeof address === 'string' ? address : `${address.address}:${address.port}`;
logger.info(`Cognito Local running on http://${url}`);
})
.catch((err) => {
logger.error(err);
process.exit(1);
});
process.on('SIGTERM', () => process.exit(0));
process.on('SIGINT', () => process.exit(0));