This repository has been archived on 2024-11-11. You can view files and clone it, but cannot push or open issues or pull requests.

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2015-12-01 15:33:06 -04:30
var express = require('express');
var app = express();
2015-11-25 19:25:27 -04:30
var http = require('http').Server(app);
var io = require('socket.io')(http);
var socketioJwt = require('socketio-jwt');
2015-12-01 15:33:06 -04:30
var dotenv = require('dotenv');
2015-11-25 19:25:27 -04:30
2015-12-01 15:33:06 -04:30
dotenv.load();
2015-11-25 19:25:27 -04:30
2015-12-01 15:33:06 -04:30
var env = {
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
2016-04-28 00:44:50 +03:00
AUTH0_DOMAIN: process.env.AUTH0_DOMAIN
};
var port = process.env.PORT || 3001;
2015-12-01 15:33:06 -04:30
2016-04-28 00:44:50 +03:00
app.set('views', __dirname + '/views');
app.set('view engine', 'pug');
2015-11-25 19:25:27 -04:30
io
.on('connection', socketioJwt.authorize({
2015-12-01 15:33:06 -04:30
secret: Buffer(JSON.stringify(process.env.AUTH0_CLIENT_SECRET), 'base64'),
2015-11-25 19:25:27 -04:30
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 15:33:06 -04:30
app.use(express.static(__dirname + '/public'));
2015-12-01 15:33:06 -04:30
app.get('/', function (req, res) {
2016-04-28 00:44:50 +03:00
res.render('index', { env: env });
});
2015-11-25 19:25:27 -04:30
http.listen(port, function(){
console.log('listening on *:' + port);
2015-11-25 19:25:27 -04:30
});
2015-12-01 15:33:06 -04:30