-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
40 lines (30 loc) · 1.1 KB
/
server.js
File metadata and controls
40 lines (30 loc) · 1.1 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
/**
* This file sets up the Express server, configures middleware, and defines routes for the application.
* It also includes a health check endpoint to verify that the server is running properly.
* @Author: Chamod Dilshan
* @abstract: This server serves as the backend for the user management system, handling API requests related to user operations.
* @Date: 2026-02-10
* @Version: 1.0
*/
const express = require('express');
const cors = require('cors');
const path = require('path');
const dotenv = require('dotenv');
dotenv.config();
const app = express();
const PORT = process.env.PORT;
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const userRoute = require('./src/routes/user.route');
app.use('/api/users', userRoute);
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public/static/index.html'));
});
app.get('/health', (req, res) => {
res.sendFile(path.join(__dirname, 'public/static/health.html'));
});
if (process.env.NODE_ENV !== 'test') {
app.listen(PORT, () => console.log(`Server is running on port ${PORT}`));
}
module.exports = app;