-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
56 lines (45 loc) · 1.85 KB
/
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
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
const express = require('express');
const bodyParser = require('body-parser')
const path = require('path');
const app = express();
const encryptPassword = require('encrypt-password');
var db = require('./database');
const WebSocket = require('ws');
const socket_request = require("./websocket/socket.js");
const {createServer} = require('http');
/*for live server */
// Serve the static files from the React app
// app.use(express.static(path.join(__dirname, 'client/build')));
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(bodyParser.json());
/*for local use*/
app.use(express.static(path.join(__dirname, 'build')));
app.use('/api/login', require('./routes/login'));
app.use('/api/patient', require('./routes/patient'));
app.use('/api/doctor', require('./routes/doctor'));
app.use('/api/chat', require('./routes/chat'));
const port = process.env.PORT || 5000;
const server = createServer(app);
server.listen(port, () => console.info(`Server running on port: ${port}`));
const wss = new WebSocket.Server({ server });
socket_request.handle_request(wss, WebSocket)
db.query('SELECT NOW()', (err, res) => {
if (err.error)
return console.log(err.error);
console.log(`PostgreSQL connected: ${res[0].now}.`);
/*
*
*
* FOLLOWING PART IS MANDATORY THE FIRST TIME THE SERVER RUNS ONLY
* AFTERWARDS OPTINIONAL (TO RESET DB)
*
*
*/
const table_doctor = require("./db_script/table_doctor.js");
const table_patient = require("./db_script/table_patient.js");
const table_chat = require("./db_script/table_chat.js");
const table_pharmacy = require("./db_script/table_pharmacy.js");
const table_patientToDoctor = require("./db_script/table_patientToDoctor.js"); // at the moment not in use, maybe for future work
const table_address = require("./db_script/table_address.js"); // at the moment not in use, maybe for future work
});