forked from sejalgupta3/Diabetes-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (53 loc) · 1.68 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var express = require('express');
var path = require('path');
var server = require('./app');
var app = express();
var http = require('http')
var patient = require('./routes/patient');
var doctor = require('./routes/doctor');
var db = require('./db')
var bodyParser = require('body-parser');
var databaseName = 'dms';
app.use(bodyParser());
app.set('port', process.env.PORT || 9000);
// Serve static assets
app.use(express.static(path.resolve(__dirname, '..', 'build')));
app.use('/patient', patient);
app.use('/doctor', doctor);
app.post('/socketEmit', function(req, res) {
var id =req.param("id");
var name = req.param("name");
if(connection){
io.emit('chat message', { id : id,name :name});
res.end("Success");
res.send();
}else{
console.log('No client connected');
}
});
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
// Always return the main index.html, so react-router render the route in the client
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, '..', 'build', 'index.html'));
});
// Connect to Mongo on start
db.connect('mongodb://localhost:27017/'+databaseName, function(err) {
if (err) {
console.log(err);
process.exit(1);
}
})
var server = http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
var io = require('socket.io')(server);
// socket.io demo
io.on('connection', function(socket){
console.log("connection establised");
connection = true;
})
module.exports = app;