-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
49 lines (39 loc) · 1.36 KB
/
app.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
45
46
47
48
49
import express from "express";
import * as http from "http";
import * as winston from 'winston';
import * as expressWinston from 'express-winston';
import cors from 'cors';
import { CommonRoutesConfig } from "./common/common.routes.config";
import { UsersRoutes } from "./users/users.routes.config";
import debug from "debug";
import dotenv from "dotenv";
dotenv.config();
const app: express.Application = express();
const server: http.Server = http.createServer(app);
const port = 3000 || process.env.PORT;
const routes: Array<CommonRoutesConfig> = [];
const debugLog: debug.IDebugger = debug("app");
app.use(express.json());
const loggerOptions: expressWinston.LoggerOptions = {
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.json(),
winston.format.prettyPrint(),
winston.format.colorize({ all: true })
),
};
if (!process.env.DEBUG) {
loggerOptions.meta = false;
}
app.use(expressWinston.logger(loggerOptions));
routes.push(new UsersRoutes(app));
const message = `server running on http://localhost:${port}`;
app.get("/", (req: express.Request, res: express.Response) => {
res.status(200).send(message);
});
server.listen(port, () => {
routes.forEach((route: CommonRoutesConfig) => {
debugLog(`Routes configured for ${route.getName()}`);
});
console.log(message);
});