This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
59 lines (51 loc) · 1.88 KB
/
app.js
File metadata and controls
59 lines (51 loc) · 1.88 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require('dotenv').config();
const {connectToCluster} = require('./database/mongodb');
const cors = require('cors');
const express = require('express');
const app = express();
const userRoutes = require('./routes/index');
const patientRoutes = require('./routes/patient');
const doctorRoutes = require('./routes/doctor');
const adminRoutes = require('./routes/admin');
const immigrationOfficialRoutes = require('./routes/immigrationOfficial');
const healthOfficialRoutes = require('./routes/healthOfficial');
const notificationRoutes = require('./routes/notification');
const bodyParser = require('body-parser');
const createWebSocketConnection = require('./WebSockets/socketIO');
const path = require('path');
const port = process.env.PORT || 3001;
const socketio = require('socket.io');
require('colors');
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use('/user', userRoutes);
app.use('/patient', patientRoutes);
app.use('/doctor', doctorRoutes);
app.use('/admin', adminRoutes);
app.use('/immigration-official', immigrationOfficialRoutes);
app.use('/health-official', healthOfficialRoutes);
app.use('/notification', notificationRoutes);
if (process.env.NODE_ENV === 'production') {
// Serve any static files
app.use(express.static(path.join(__dirname, 'frontend/build')));
// Handle React routing, return all requests to React app
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'frontend/build', 'index.html'));
});
}
const server = app.listen(port, () => {
console.log(`Server listening on port ${port}...`.brightBlue);
});
connectToCluster(process.env.MONGO_CLUSTER_URL).then((client) => {
app.locals.mongodb = client;
createWebSocketConnection(client, server);
});
process.on('exit', () => {
server.close();
});
process.on('SIGTERM', () => {
server.close();
});
module.exports = app;
module.exports.server = server;