-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (27 loc) · 1005 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
const express = require("express");
const cookieParser = require("cookie-parser");
const AppError = require("./utils/AppError");
const errorController = require("./controllers/errorController");
const userRoutes = require("./routes/userRoutes");
const profileRoutes = require("./routes/profileRoutes");
const postRoutes = require("./routes/postRoutes");
const path = require("path");
const app = express();
app.use(express.json());
app.use(cookieParser());
app.use("/api/users", userRoutes);
app.use("/api/profiles", profileRoutes);
app.use("/api/posts", postRoutes);
// SERVE STATIC ASSETS IN PRODUCTION
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
app.all("*", (req, res, next) => {
console.log(req.url);
return next(new AppError(404, "The route was not found !"));
});
app.use(errorController.errorHandler);
module.exports = app;