-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobisos-server.js
68 lines (48 loc) · 1.4 KB
/
mobisos-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
/**
* Global namespace & imports
*/
const NODE_HTTP_PORT = 1337;
var express = require('express')
, cors = require('cors')
, app = express()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)
, ctrl = require('./ctrl/index');
/**
* Main program section
*/
ctrl.setSocketIo(io);
app.configure(function () {
app.use(cors());
//app.use(app.router);
app.use(express.logger('dev')); /* 'default', 'short', 'tiny', 'dev' */
app.use(express.bodyParser());
});
/**
* route definitions
*/
// RESTful Resources
app.get('/hello', ctrl.hello);
app.get('/users', ctrl.findAll);
app.get('/users/:id', ctrl.findById);
app.post('/users', ctrl.addUser);
app.put('/users/:id', ctrl.updateUser);
app.delete('/users/:id', ctrl.deleteUser);
// SOS functions
app.post('/tracking', ctrl.tracking);
app.post('/soscall', ctrl.sosCall);
app.post('/wifi.checkin', ctrl.wifiCheckin);
app.post('/tag.checkin', ctrl.tagCheckin);
app.post('/checkin', ctrl.checkin);
app.get('/checkin/:uuid/:from/:until', ctrl.getCheckin);
// Starting the server
//app.listen(NODE_HTTP_PORT); // commented out for socket.io compliant
server.listen(NODE_HTTP_PORT, function() {
console.log('Node.js HTTP Server started at PORT:' + NODE_HTTP_PORT + '...');
});
// Socket.io
io.sockets.on('connection', function (socket) {
socket.on('notifyFromClient', function (data) {
console.log(data);
});
});