-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
33 lines (29 loc) · 1.19 KB
/
server.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
import * as dotenv from "dotenv";
dotenv.config();
import express, { Request, Response, Application, Errback, NextFunction, Router } from 'express';
import connect from './configuration/connect';
import * as properties from './configuration/properties';
import bodyParser from 'body-parser';
import { MainRouter } from './router'
// Create a new express app instance
const app: Application = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.get('/', (req: Request, res: Response) => {
res.status(200).json({ message: "happy holidays !!" })
});
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,HEAD');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});
app.use(MainRouter);
app.use((err: Errback, req: Request, res: Response, next: NextFunction) => {
res.status(500).json({ message: err.name });
});
app.listen(properties.Config.PORT, () =>
console.log(`Application started successfully on port ${properties.Config.PORT}.`)
);
const db = properties.Config.MONGO_URL
connect({ db });