-
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) · 737 Bytes
/
server.js
File metadata and controls
31 lines (24 loc) · 737 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
import express from "express";
import cors from "cors";
import records from "./server/routes/sales.js";
import users from "./server/routes/users.js";
const PORT = process.env.PORT || "";
const app = express();
// middleware
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// Serve static files from the React app
app.use(express.static('./client/dist'));
// routes
app.use("/", records);
app.use("/record", records);
app.use("/users", users);
// serves the index.html with catchall route
app.get("*", (req, res) => {
res.sendFile('client/dist/index.html', { root: '.' });
});
// start the Express server
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});