-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (30 loc) · 1.1 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
const express = require("express");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const logger = require("morgan");
const errorhandler = require("errorhandler");
const appConfig = require("./config/app-config");
const statusCodes = require("./constants/http-status-codes");
const app = express();
require("./models/connection");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(logger("dev"));
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "POST, GET, DELETE, PUT, OPTIONS");
res.setHeader("Access-Control-Allow-Credentials", "true");
res.setHeader("Access-Control-Allow-Headers", "*");
next();
});
require("./routes")(app);
app.use((req, res, next) => {
res.status(statusCodes.NOT_FOUND).send("<h1>Page not found</h1>");
});
if (process.env.NODE_ENV === "development") {
app.use(errorhandler());
}
app.listen(appConfig.PORT, () => {
console.log(`Server started on port ${appConfig.PORT}`);
});