-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (23 loc) · 865 Bytes
/
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
const express = require('express');
const bodyParser = require('body-parser');
const connectDB = require('./src/config/database');
const app = express();
const port = 3000;
// Import middleware
const authenticate = require('./src/middleware/authentication');
const errorHandler = require('./src/middleware/errorHandling');
// Import routes
const demoRouter = require('./src/api/demo/router');
const adminRouter = require('./src/api/admin/router');
// Connect to the database
connectDB();
// Configure middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Use authentication middleware for specific routes
app.use('/api/demo', authenticate, demoRouter);
// Error handling middleware
app.use(errorHandler);
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});