2015-12-01 21:03:06 +01:00
|
|
|
var express = require('express');
|
|
|
|
var app=express();
|
2015-11-26 00:55:27 +01:00
|
|
|
var http = require('http').Server(app);
|
|
|
|
var io = require('socket.io')(http);
|
|
|
|
var socketioJwt = require('socketio-jwt');
|
2015-12-01 21:03:06 +01:00
|
|
|
var dotenv = require('dotenv');
|
2015-11-26 00:55:27 +01:00
|
|
|
|
2015-12-01 21:03:06 +01:00
|
|
|
dotenv.load();
|
2015-11-26 00:55:27 +01:00
|
|
|
|
2015-12-01 21:03:06 +01:00
|
|
|
var env = {
|
|
|
|
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
|
|
|
|
AUTH0_DOMAIN: process.env.AUTH0_DOMAIN,
|
|
|
|
}
|
|
|
|
|
|
|
|
app.set('views', __dirname + '/views')
|
|
|
|
app.set('view engine', 'jade');
|
2015-11-26 00:55:27 +01:00
|
|
|
|
|
|
|
io
|
|
|
|
.on('connection', socketioJwt.authorize({
|
2015-12-01 21:03:06 +01:00
|
|
|
secret: Buffer(JSON.stringify(process.env.AUTH0_CLIENT_SECRET), 'base64'),
|
2015-11-26 00:55:27 +01:00
|
|
|
timeout: 15000 // 15 seconds to send the authentication message
|
|
|
|
}))
|
|
|
|
.on('authenticated', function(socket){
|
|
|
|
console.log('connected & authenticated: ' + JSON.stringify(socket.decoded_token));
|
|
|
|
socket.on('chat message', function(msg){
|
|
|
|
debugger;
|
|
|
|
io.emit('chat message', msg);
|
|
|
|
});
|
|
|
|
});
|
2015-12-01 21:03:06 +01:00
|
|
|
|
|
|
|
app.use(express.static(__dirname + '/public'));
|
|
|
|
|
|
|
|
app.get('/', function (req, res) {
|
|
|
|
res.render('index',
|
|
|
|
{ env: env }
|
|
|
|
|
|
|
|
)
|
|
|
|
})
|
2015-11-26 00:55:27 +01:00
|
|
|
|
|
|
|
http.listen(3001, function(){
|
|
|
|
console.log('listening on *:3001');
|
|
|
|
});
|
2015-12-01 21:03:06 +01:00
|
|
|
|