forked from jagregory/cognito-local
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.ts
41 lines (37 loc) · 1.09 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
#!/usr/bin/env node
import { createDefaultServer } from "../server";
import Pino from "pino";
import PinoPretty from "pino-pretty";
const logger = Pino(
{
level: process.env.DEBUG ? "debug" : "info",
},
PinoPretty({
colorize: true,
ignore: "pid,name,hostname",
singleLine: true,
messageFormat: (log, messageKey) =>
`${log["reqId"] ?? "NONE"} ${log["target"] ?? "NONE"} ${log[messageKey]}`,
}) as any // eslint-disable-line @typescript-eslint/no-explicit-any
);
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);
});