-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (38 loc) · 1.07 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
const express = require('express');
const router = require("./src/routes/api")
const app = new express();
const bodyParser = require('body-parser');
// Security Middleware Import
const rateLimit = require('express-rate-limit')
const helmet = require('helmet')
const mongoSanitize = require('express-mongo-sanitize')
const xss = require('xss-clean')
const hpp = require('hpp')
const cors = require('cors')
const mongoose = require('mongoose')
// Security Middleware Implement
app.use(cors())
app.use(helmet())
app.use(mongoSanitize())
app.use(xss())
app.use(hpp())
app.use(bodyParser.json())
// Request rate limiting
const limiter = rateLimit({
windowMs: 15*60*1000,
max: 100
})
app.use(limiter)
// Mongo DB Database Connection
let URI = "mongodb://127.0.0.1:27017/Schools"
let OPTION = {user: '', pass: ''}
mongoose.connect(URI,OPTION, (error) => {
console.log('Connection Success...');
console.log(error);
})
app.use("/api/v1",router);
// Undefined Route
app.use('*',(req,res)=> {
res.status(404).json({status: "fail", data: "Not Found"})
})
module.exports=app;