-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
46 lines (38 loc) · 1.17 KB
/
Copy pathserver.js
File metadata and controls
46 lines (38 loc) · 1.17 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
var express = require('express');
var app = express();
var links = require('docker-links').parseLinks(process.env);
var client = require('socket.io-client')('https://' + links.store.hostname + ':' + links.store.port);
app.use(function(req, res, next) {
console.log('got req, ' + req.url);
next();
});
app.engine('engine', require('ejs-locals'));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/public'));
app.use(express.bodyParser());
app.get('/', function(req, res) {
res.render('index');
});
app.get('/data', function(req, res) {
console.log('getting all');
client.emit('getAll', function(data) {
console.log('got all', data);
res.json(data);
});
});
app.post('/data', function(req, res) {
console.log('about to save', req.body);
client.emit('save', req.body.body, function() {
console.log('got result');
res.json({success: true});
});
});
app.use(function(req, res) {
res.writeHead(404, {'Content-Type': 'text/plain'});
res.write('Page not found!');
res.end();
});
var server = app.listen(doskara.ports.main, function() {
console.log('listening on port ' + doskara.ports.main);
});