-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (27 loc) · 1019 Bytes
/
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
const express = require("express");
const morgan = require("morgan");
const cookieParser = require("cookie-parser");
const AppError = require("./utils/appError");
const globalErrorHandler = require("./controllers/errorController");
const userRouter = require("./routes/userRoutes");
// const apartmentRoutes = require("./routes/apartmentRoutes");
// const reviewRouter = require("./routes/reviewRoutes");
const app = express();
// Development logging
if (process.env.NODE_ENV == "development") {
app.use(morgan("dev"));
}
// Body parser, reading data from body into req.body
app.use(express.json({ limit: "10kb" }));
app.use(cookieParser());
app.get("/test", (req, res) => {
res.json("Hello World");
});
// app.use("/api/v1/apartments", apartmentRoutes);
app.use("/api/v1/users", userRouter);
// app.use("/api/v1/reviews", reviewRouter);
app.all("*", (req, res, next) => {
next(new AppError(`Can't find ${req.originalUrl} on this server!`, 404));
});
app.use(globalErrorHandler);
module.exports = app;