-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (40 loc) · 1.34 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
var createError = require("http-errors");
var express = require("express");
var helmet = require("helmet");
var compression = require("compression");
var cors = require("cors");
var xss = require("xss-clean");
var mongoSanitize = require("express-mongo-sanitize");
const { errorHandler } = require("./middlewares/error");
var path = require("path");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
var indexRouter = require("./routes/index");
var listRouter = require("./routes/list");
var app = express();
var dbconfig = require("./config/dbconfig");
// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "jade");
app.use(helmet());
app.use(logger("dev"));
app.use(express.json({ limit: "100mb" }));
app.use(express.urlencoded({ limit: "50mb", extended: true, parameterLimit: 1000000 }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
// santiize request data
app.use(xss());
app.use(mongoSanitize());
// compress all request and responses
app.use(compression());
// enable cors
app.use(cors());
app.options("*", cors()); // allow all the origins to access the API
// Configure routes
app.use("/", indexRouter);
app.use("/list", listRouter);
// handle error
app.use(errorHandler);
// Connect to database
dbconfig.connecttoDB();
module.exports = app;