forked from abhinavrastogi/fluxocket-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (28 loc) · 817 Bytes
/
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
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var fs = require('fs');
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: '2ac54adbf4dadad2000.qb0x.com:80'
});
app.use(express.static('public'));
app.get('*', function(req, res){
res.send(fs.readFileSync('index.html', { encoding: 'utf8' }));
});
io.on('connection', function(socket){
socket.on('flux_action', function(payload) {
socket.broadcast.emit('flux_action', payload);
client.create({
index: 'fluxocket-chats',
type: 'chats',
body: payload
}, function (error, response) {
console.log(error, response);
});
});
});
http.listen(process.env.PORT || 3000, function(){
console.log('listening on *:3000');
});