-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (37 loc) · 1.3 KB
/
index.js
File metadata and controls
45 lines (37 loc) · 1.3 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
// get web framework
var express = require('express'),
bodyParser = require('body-parser'),
sockjs = require('sockjs');
var app = express();
app.set('view engine', 'jade');
app.use('/dist', express.static('dist'));
app.use('/old_dist', express.static('assets'));
app.use('/node_modules', express.static('node_modules'));
// start services
var server = require('http').createServer(app);
var connections = [];
var echo = sockjs.createServer();
echo.on('connection', function(conn) {
connections.push(conn);
conn.on('close', function() {});
});
app.get('/', function (request, response) {
response.render('index.jade');
});
app.get('/registry', function (request, response) {
response.render('registry');
});
app.get('/add-image', function (request, response) {
response.render('add_image');
});
app.post('/add-image', bodyParser.json(), bodyParser.urlencoded({ extended: true }), function (request, response) {
// emit new image to clients
console.log('New feed added');
for (var i = connections.length - 1; i >= 0; i--) {
connections[i].write(JSON.stringify({action: 'push', content: {type: 'image/jpeg', src: request.body.url}}));
};
response.render('add_image');
});
// chat server init
server.listen(9000);
echo.installHandlers(server, {prefix: '/ws'});