blob: e4f8db1ed9b7887f1c6b6e1f292c4be06ed814c4 (
plain) (
blame)
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
45
46
47
48
|
import dotenv from "dotenv";
import express from "express";
import winston from "winston";
import expressWinston from "express-winston";
dotenv.config();
import routes from "./routes";
import Metadata from "./metadata";
import loggerConfig from "./util/logger";
import { handleStartup, handleShutdown } from "./util/config";
// Start-up configuration
const BIND_ADDRESS = process.env.BIND_ADDRESS ?? "localhost";
const MONGO_DB = process.env.MONGO_DB ?? "ao-coverage";
const PORT = Number(process.env.PORT ?? 3000);
const logger = winston.createLogger(loggerConfig("ROOT"));
handleStartup().then(mongo => {
const app: express.Application = express();
const metadata = new Metadata(mongo.db(MONGO_DB));
app.use(
expressWinston.logger({
...loggerConfig("HTTP"),
colorize: true,
// filter out token query param from URL
msg:
'{{req.method}} {{req.url.replace(/token=[-\\w.~]*(&*)/, "token=$1")}} - {{res.statusCode}} {{res.responseTime}}ms'
})
);
// actual app routes
app.use(routes(metadata));
app.use(expressWinston.errorLogger(loggerConfig("_ERR")));
const server = app.listen(PORT, BIND_ADDRESS, () => {
logger.info("Express has started: http://%s:%d/", BIND_ADDRESS, PORT);
});
// application exit handling
const signalCodes: NodeJS.Signals[] = ["SIGTERM", "SIGHUP", "SIGINT"];
signalCodes.map((code: NodeJS.Signals) => {
process.on(code, handleShutdown(mongo, server));
});
});
|