-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (58 loc) · 1.75 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const app = express();
// Configuration
const BACKEND_PORT = process.env.PORT;
const IP = process.env.IP;
const FPORT = process.env.FPORT;
const { MONGODB, DB_NAME } = process.env;
// Data loading
const loadData = require('./drugDB/loadData');
const loadAllData = require('./drugDB/loadAllData');
// Routes
const authRoutes = require('./routes/authRoutes');
const drugRoutes = require('./routes/drugRoutes');
const userRoutes = require('./routes/userRoutes');
const profileRoutes = require('./routes/profileRoutes');
const medicationRoutes = require('./routes/medicationRoutes');
const aBuddyRoutes = require('./routes/aBuddyRoutes');
const doctorRoutes = require('./routes/doctorRoutes');
const pharmacyRoutes = require('./routes/pharmacyRoutes');
// Cron jobs - Notifications
require('./helpers/cronNotifications');
// Middlewares
const errorHandler = require('./middlewares/errorHandler');
// Database connection
const db = require('./helpers/db');
db()
.then(() => {
console.log(`Database connected to: ${MONGODB}/${DB_NAME}`);
// loadData();
loadAllData();
})
.catch((err) => console.error(err));
// CORS
app.use(
cors({
origin: `${IP}:${FPORT}`,
credentials: true,
})
);
// Middleware setup
app.use(express.json());
// Route setup
app.use('/', authRoutes);
app.use('/drugs', drugRoutes);
app.use('/user', userRoutes);
app.use('/user', profileRoutes);
app.use('/user', medicationRoutes);
app.use('/user', aBuddyRoutes);
app.use('/user', doctorRoutes);
app.use('/user', pharmacyRoutes);
// Error handling
app.use(errorHandler);
// Server setup
app.listen(BACKEND_PORT, () => {
console.log(`Server is running on ${IP}:${BACKEND_PORT}`);
});