-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (40 loc) · 1.07 KB
/
server.js
File metadata and controls
53 lines (40 loc) · 1.07 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
var express = require('express'),
http = require('http'),
socket = require('socket.io'),
port = 80,
server, io, app;
function emit(type, data) {
io.sockets.emit(type, data);
}
function routeFiles() {
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
app.use(express.static(__dirname + '/'));
}
function routeActions() {
app.get('/update', function (req, res) {
var id = req.param("id", null),
lat = req.param("lat", null),
lng = req.param("lng", null);
emit('update', {id: id, geo: {lat: lat, lng: lng}});
res.send('thx');
});
app.get('/delete', function (req, res) {
var id = req.param("id", null);
emit('delete', {id: id});
res.send('thx');
});
}
function openSockets() {
io.sockets.on('connection', function () {
});
}
app = express();
server = http.createServer(app);
server.listen(port);
io = socket.listen(server, {log: false});
openSockets();
routeFiles();
routeActions();
console.log('Listening on port ' + port);