-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (35 loc) · 1.07 KB
/
index.js
File metadata and controls
40 lines (35 loc) · 1.07 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
//IMPORTS*******************************************
require("dotenv/config");
const cors = require("cors");
const express = require("express");
const routes = require("./server/src/routes");
const path = require("path");
const baseDir = path.resolve("client", "build");
//DEFINE APP*****************************************
const app = express();
app.use(express.json());
app.use(cors());
app.use(routes);
app.use(express.static(`${baseDir}`));
//RETURN FRONT-END ***********************************
app.get("*", (request, response) => {
if (process.env.ENV === "prod") {
response.sendFile("index.html", { root: baseDir });
} else {
return response.json({
Environment: "Development",
});
}
});
//CATCH INTERNAL ERROR*******************************
app.use((error, request, response, next) => {
response.status(error.status || 500);
response.json({ error: error.message });
});
app.use((request, response, next) => {
const eroor = new Error("Not Found");
error.status = 404;
next(error);
});
//LISTEN PORT*****************************************
app.listen(process.env.PORT);