-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (25 loc) · 783 Bytes
/
Copy pathserver.js
File metadata and controls
32 lines (25 loc) · 783 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
import express from "express";
import cors from "cors";
import dotenv from "dotenv";
import ediRoutes from "./routes/ediRoutes.js";
import path from "path";
import { fileURLToPath } from "url";
dotenv.config();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
const PORT = process.env.PORT || 5000;
app.use(cors());
app.use(express.json());
// API Routes
app.use("/api", ediRoutes);
// Serve static frontend in production
if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, "dist")));
app.get(/.*/, (req, res) => {
res.sendFile(path.join(__dirname, "dist", "index.html"));
});
}
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});