-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (29 loc) · 962 Bytes
/
index.js
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
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const path = require("path");
require("dotenv").config();
require("./Models/db"); // Ensure database connection is correctly set up
const app = express();
const PORT = 5000;
// Middleware
app.use(bodyParser.json());
// CORS Configuration
const corsOptions = {
origin: "http://localhost:3000", // Change this to your frontend URL
credentials: true,
};
app.use(cors(corsOptions));
// Import Routes
const SinLog = require("./Routes/SinLog");
app.use("/qr-code-system", SinLog);
// Serve Frontend (Ensure 'build' is correct, not 'dist')
const _dirname = path.resolve();
app.use(express.static(path.join(_dirname, "my-app/build")));
app.get("*", (req, res) => {
res.sendFile(path.resolve(_dirname, "my-app", "build", "index.html"));
});
// Start Server
app.listen(PORT, () => {
console.log(`🚀 Server running on port ${PORT}`);
});