-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (34 loc) · 977 Bytes
/
Copy pathserver.js
File metadata and controls
39 lines (34 loc) · 977 Bytes
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
import express from "express";
import morgan from "morgan";
import cors from "cors";
import helmet from "helmet";
import bodyParser from "body-parser";
import Config from "./configuration/Config";
import path from "path";
import Routing from "./routes/Routing";
const app = express();
app.use(cors());
app.use(morgan("combined"));
app.use(
helmet({
contentSecurityPolicy: false,
})
);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(function (req, res, next) {
next();
if (res.statusCode >= 400) throw new Error(`at ${req.method} ${req.path}`);
});
Routing.setRoutes(app);
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"));
});
}
// Apply Middleware
// app.use(Middleware.notFound);
// app.use(Middleware.errorHandler);
Config.startServer(app);
Config.connectToMongoDB();