-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
62 lines (47 loc) · 1.69 KB
/
app.js
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
//Import Configured Files
const mongoConnect = require('./config/database');
//Import Installed Libaries here
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const fileUpload = require("express-fileupload");
const cors = require('cors');
const helmet = require('helmet');
const path = require('path');
const xss = require("xss-clean");
const dotenv = require('dotenv');
const mongoSanitize = require("express-mongo-sanitize");
dotenv.config();
//Import Environment Variables
const port =process.env.port || 4000;
const express = require('express');
const app = express();
//Import Routers
const notFoundMiddleware= require('./middlewares/4O4NotFound.js')
const errorHandlerMiddleware = require('./middlewares/Errorhandler.js')
const adminRouter = require('./routers/adminRouter.js');
const userRouter = require('./routers/userRouter.js');
const commonRouter = require('./routers/commonRouter.js');
//middleware Stack
app.use(bodyParser.json({ limit: '25mb' }));
app.use(cookieParser(process.env.COOKIES_SECRET));
app.use('/public', express.static(path.join(__dirname, 'public')));
app.use(fileUpload());
app.use(xss());
app.use(mongoSanitize());
app.use(helmet());
const allowedOrigins = [
'http://localhost:3000'
];
app.use(cors({ origin: allowedOrigins, credentials: true }));
//module Router Stack
app.use('/api/v1/admin',adminRouter);
app.use('/api/v1/user',userRouter);
app.use('/api/v1/common',commonRouter);
app.use(notFoundMiddleware);
app.use(errorHandlerMiddleware);
app.listen(port,(err)=>{
(!err)?
console.log('listening on port',port):
console.log(err);
})
mongoConnect();