-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (33 loc) · 1.29 KB
/
server.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
37
38
39
40
41
const express = require('express');
const dotenv = require('dotenv');
const morgan = require('morgan');
const connectDB = require('./config/db');
const cors = require('cors');
const path = require('path'); // Required for resolving paths
// dotenv config
dotenv.config();
// initialize express
const app = express();
// MONGO DB CONNECTION
connectDB();
// Middlewares
app.use(cors()); // CORS Middleware
app.use(morgan('dev')); // Logging Middleware
app.use(express.json()); // Body Parsing Middleware
app.use(express.urlencoded({ extended: false })); // URL-Encoded Parsing Middleware
// API Routes
app.use("/api/v1/user", require('./routes/userRoutes'));
app.use("/api/v1/admin", require('./routes/adminRoutes'));
app.use("/api/v1/changeAccountStatus", require('./routes/adminRoutes'));
app.use("/api/v1/doctor", require('./routes/doctorRoutes'));
// Serve static files from the React app
app.use(express.static(path.join(__dirname, 'client', 'dist')));
// Catch-all route to serve the React app's index.html for unknown paths
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "dist", "index.html"));
});
// Set and start the server on the correct port
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});