-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (32 loc) · 1012 Bytes
/
app.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
42
43
44
import { logger } from './logger/logger.js';
import { slotRoutes } from './routes/slotRoutes.js';
import { parkingRoutes } from './routes/parkingRoutes.js';
import { parkingLotRoutes } from './routes/parkingLotRoutes.js';
import bodyParser from 'body-parser';
import express from 'express';
const app = express();
app.use(bodyParser.json());
app.use((req, res, next) => {
logger.info(`${req.method} ${req.url}`);
next();
});
app.use((err, req, res, next) => {
logger.error(err.stack);
res.status(500).send('Something went wrong!');
});
app.use('/api/ParkingLots', parkingLotRoutes);
app.use('/api/Parkings', parkingRoutes);
app.use('/api/Slots', slotRoutes);
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({
isSuccess: false,
error: {
reason: 'Internal Server Error',
},
});
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});