Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
52 lines (43 loc) 路 1.79 KB
/
Copy pathserver.js
File metadata and controls
52 lines (43 loc) 路 1.79 KB
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
42
43
44
45
46
47
48
49
50
51
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const cors = require('cors'); // Make sure cors is required
const Users = require('./routes/users');
const Patient = require('./routes/users/Patient/patient');
const Employee = require('./routes/users/Employee/employee');
const Doctor = require('./routes/users/Doctor/docter');
const Admin = require('./routes/users/Administrator/admin');
const superAdmin = require('./routes/users/Administrator/superAdmin');
const api = require('./routes/api/api');
const app = express();
// --- Middleware ---
app.use(cors()); // Enable CORS
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// --- ADD THIS LOGGING MIDDLEWARE ---
app.use((req, res, next) => {
console.log(`>>> Incoming Request: ${req.method} ${req.originalUrl}`);
next(); // Pass control to the next middleware/route
});
// ------------------------------------
// --- API Routes ---
// It's slightly better practice to put API routes before static files
app.use('/users', Users);
app.use('/patient', Patient);
app.use('/employee', Employee);
app.use('/doctor', Doctor);
app.use('/admin', Admin);
app.use('/super', superAdmin);
app.use('/api', api);
// --- Static Files ---
// Serve static files from the React build directory
app.use(express.static(path.join(__dirname, 'client/build')));
// --- Catch-all Route ---
// For any other request, send back the main index.html file (for client-side routing)
app.use('/*', (req, res) => {
console.log(`>>> Catch-all sending index.html for ${req.method} ${req.originalUrl}`);
res.sendFile(path.join(__dirname, 'client/build/index.html'));
});
// --- Server Start ---
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`馃殌 Server started at port ${PORT}`));