-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
52 lines (41 loc) · 1.37 KB
/
app.js
File metadata and controls
52 lines (41 loc) · 1.37 KB
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
const express = require("express");
const path = require("path");
const bodyParser = require("body-parser");
const cors = require("cors");
const cookieParser = require("cookie-parser");
const userRouter = require("./routes/userRoutes");
const stateRouter = require("./routes/stateRoutes");
const viewRouter = require("./routes/viewRoutes");
const AppError = require("./utils/appError");
const globalErrorHandler = require("./controllers/errorController");
const app = express();
// app.enable("trust proxy");
app.use(cookieParser());
// app.use(cors());
// app.use(cors({ origin: true, credentials: true }));
app.post(bodyParser.raw({ type: "application/json" }));
app.use(bodyParser.json());
// app.options("*", cors());
app.set("view engine", "pug");
app.set("views", path.join(__dirname, "views"));
app.use(express.static(path.join(__dirname, "static")));
app.use(express.urlencoded({ extended: true, limit: "10kb" }));
app.use("/", viewRouter);
app.use("/api/v1/users", userRouter);
app.use("/api/v1/requests", stateRouter);
app.use("*", (req, res, next) => {
next(
new AppError(
`The url ${req.originalUrl} can't be found on this server.`,
404
)
);
});
process.once("SIGUSR2", function () {
process.kill(process.pid, "SIGUSR2");
});
process.on("SIGINT", function () {
process.kill(process.pid, "SIGINT");
});
app.use(globalErrorHandler);
module.exports = app;