-
Notifications
You must be signed in to change notification settings - Fork 0
/
sheer.js
52 lines (39 loc) · 1.43 KB
/
sheer.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var express = require('express');
var http = require('http');
var path = require('path');
var hbs = require('hbs');
var bodyParser = require('body-parser');
var favicon = require('serve-favicon');
var methodOverride = require('method-override');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var routes = require('./routes');
var clock = require('./routes/clock');
var app = express();
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
app.engine('html', hbs.__express);
//app.use(favicon(__dirname + '/public/favicon.ico'));
//app.use(express.logger('dev'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//app.use(express.json());
app.use(methodOverride());
app.use(cookieParser('your secret here'));
//app.use(session());
app.use(express.static(path.join(__dirname, 'public')));
app.all('/', clock.idate);
var server = app.listen(app.get('port'), function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
var io = require('socket.io').listen(server);
io.sockets.on('connection', function(socket){
socket.emit('news', {hello: 'world'});
console.log('Received websocket connection.');
setInterval(function(){
socket.emit('date', {'date': new Date()});
}, 1000);
});