-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
58 lines (48 loc) · 1.38 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
// Basic Lib Import
const express = require("express");
const app = new express();
const router = require("./src/routes/api");
// Security Middleware Lib 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 morgan = require("morgan");
const nocache = require("nocache");
const bodyParser = require("body-parser");
require("dotenv").config();
// Database Lib Import
const mongoose = require("mongoose");
// Security Middleware Implement
app.use(cors());
app.use(helmet());
app.use(mongoSanitize());
app.use(xss());
app.use(hpp());
app.use(morgan("dev"));
app.use(nocache());
app.use(express.json({ limit: "50mb" }));
app.use(express.urlencoded({ limit: "50mb" }));
// Body Parser Implement
app.use(bodyParser.json());
// Request Rate Limit
const limiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 3000 });
app.use(limiter);
// Mongo DB Database Connection
mongoose
.connect(process.env.URL)
.then((value) => {
console.log("Database Connected Success");
})
.catch((err) => {
console.log(err);
});
// Routing Implement
app.use("/api/v1", router);
// Undefined Route Implement
app.use("*", (req, res) => {
res.status(404).json({ status: "fail", data: "Not Found" });
});
module.exports = app;