-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
62 lines (51 loc) · 1.48 KB
/
index.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
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* ENVIRONMENT LOADING
*/
import * as dotenv from 'dotenv';
if (process.env.MODE === "dev") {
dotenv.config();
}
/*
* EXTERNAL DEPENDENCIES
*/
import * as cors from 'cors';
import * as express from 'express';
import { Request, Response } from 'express'
import * as morgan from 'morgan';
import { connect, connected } from './Helpers/MongoConnection';
const expressApp = express();
import * as bodyParser from 'body-parser';
import logger, { LoggerStream } from './Utils/Logger';
import { backResponse } from './Middlewares/backResponse';
import { ResponseType } from './Types/responseTypes'
/*
* Express CONFIGURATION
*/
expressApp.use(cors());
expressApp.use(bodyParser.urlencoded({ extended: true }));
expressApp.use(backResponse);
expressApp.use(morgan("combined", { stream: new LoggerStream() }));
/*
* ROUTES CONFIGURATION
*/
expressApp.use((req : Request, res : Response) => {
res.backResponse(ResponseType.BAD_REQUEST_NOT_FOUND(req.url));
});
function mongoConnect() {
connect(process.env.MONGO_IP, process.env.MONGO_PORT === "null" ? undefined : Number(process.env.MONGO_PORT), process.env.MONGO_DB, process.env.MONGO_USER, process.env.MONGO_PASSWORD);
return connected();
}
/**
* Main function, Bridge entry point
*
* @async
* @function main
*/
export async function main() {
await mongoConnect();
logger.info(`ENVIRONMENT : ${process.env.NODE_ENV}`);
expressApp.listen(process.env.BRIDGE_PORT, async () => {
logger.info(`listening on port ${process.env.BRIDGE_PORT}`);
});
}
main();