-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (24 loc) · 801 Bytes
/
server.js
File metadata and controls
31 lines (24 loc) · 801 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
require("dotenv").config();
const path = require("path");
const express = require("express");
const app = express();
app.use(express.json());
/*
All your api endpoints should be prefixed with /api and be before the next ones
If you have many endpoints, consider use Express Router for each set of endpoints
*/
app.get("/api/hello-world", (req, res) => {
res.status(200).json("Hello Everyone");
});
if (process.env.NODE_ENV === "production") {
// Serve any static file
app.use(express.static(path.join(__dirname, "client/build")));
// Handle React routing, return all requests to React app
app.get("/*", (req, res) => {
res.sendFile(path.join(__dirname, "client/build", "index.html"));
});
}
const { PORT } = process.env;
app.listen(PORT, () => {
console.log("listening");
});