forked from KardiaIO/kardia-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
66 lines (51 loc) · 2.1 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
57
58
59
60
61
62
63
64
65
66
var express = require('express');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var favicon = require('serve-favicon');
// Request handlers
// User authentication routes
var user = require('./server/users/user-controller.js');
// Data query routes
var data = require('./server/data/data-controllers.js');
var errors = require('./server/error-handlers.js');
var app = express();
//Python server connection
// var python = require('./server/python/pythonComm.js');
// // Email server notification
// var email = require('./server/problematic/rhythmNotification.js');
// email.arrhythmiaNotify('Chao', 'chao.xue.mit@gmail.com', null);
app.use(express.static(__dirname + '/client'));
app.use(favicon(__dirname + '/favicon.ico'));
// var python = require('./python/pythonComm.js');
// Sends some data to Python, Python squares it - this is simply part
// of testing the python connection and can be removed later
// python.invoke("processData", [1,2,3], function(error, res, more) {
// if(error){
// throw error;
// }
// console.log(res);
// });
// For every incoming request, the following will parse the
// body of the request for its contents before passing them
// off to the other request handlers
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// User-authentication routes, handles signin, signup, and checkAuth
app.post('/users/signin', user.signin);
app.post('/users/signup', user.signup);
app.get('/users/signedin', user.checkAuth);
// If incoming request is not pinging a user authentication route
// then we make sure they are signed in by getting the token from
// the header
app.use(user.decode);
// This route is for data queries
app.post('/users/data', data.getData);
// This route is for data analysis results
app.post('/users/analysis', data.getAnalysisResults);
app.post('/users/lorenz', data.getLorenzResults);
// If there are errors from the server, use these to send back the errors
app.use(errors.errorLogger);
app.use(errors.errorHandler);
app.listen(process.env.PORT || '8080');
console.log("Server is listening...");
module.exports = app;