-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
47 lines (38 loc) · 1.08 KB
/
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
45
46
47
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const sequelize = require('./config/database');
const { relations } = require('./config/eagerLoading');
const { initDB } = require('./config/admin');
/* Required Routes */
const adminRouter = require('./routes/admin');
const nurseRouter = require('./routes/nurse');
const authRouter = require('./routes/auth');
const app = express();
const PORT = process.env.PORT || 8080;
app.use(cors());
app.use(express.json());
// Relations
relations();
app.use('/auth', authRouter);
app.use('/admin', adminRouter);
app.use(nurseRouter);
// Error Handling Middleware
app.use((error, req, res, next) => {
const status = error.statusCode || 500;
const { message, data } = error;
res.status(status).json({ message, data });
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
sequelize
// .sync({ force: true })
.sync()
.then(() => {
initDB();
console.log('Database connected successfully');
})
.catch(() => {
throw new Error('Database connection failed');
});