forked from dokku/dokku
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
75 lines (59 loc) · 2.12 KB
/
Copy pathapp.js
File metadata and controls
75 lines (59 loc) · 2.12 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var express = require('express')
, exphbs = require('express3-handlebars')
, http = require('http')
, connect = require('connect')
, io = require('socket.io');
var app = express();
app.engine('handlebars',exphbs({extname: ".html", layoutsDir:"views/", defaultLayout: 'layout'}));
app.set('view engine', 'handlebars');
/* NOTE: We'll need to refer to the sessionStore container later. To
* accomplish this, we'll create our own and pass it to Express
* rather than letting it create its own. */
var sessionStore = new connect.session.MemoryStore();
/* NOTE: We'll need the site secret later too, so let's factor it out.
* The security implications of this are left to the reader. */
var SITE_SECRET = 'I am not wearing any pants';
// app.configure(function(){
// app.set('view engine', 'handlebars');
// // app.set("view options", { layout: false })
// });
app.set('views', __dirname + '/views');
// app.register('.html', require('handlebars'));
/*
* ... skipping some of your app settings ...
*/
app.use(express.bodyParser());
/* NOTE: Pass the cookieParser the site secret. It used to be that
* express.session() got the secret, but in Express 3 that's
* no longer the case. */
app.use(express.cookieParser(SITE_SECRET));
/* NOTE: We'll need to know the key used to store the session, so
* we explicitly define what it should be. Also, we pass in
* our sessionStore container here. */
app.use(express.session({
key: 'express.sid'
, store: sessionStore
}));
app.use(express.static('public'));
/*
* ... skipping the rest of your app settings ...
*/
app.get('/', function(req, res){
res.render('index', {socket_url:"ciaourl"});
});
var server = http.createServer(app);
var app_port = process.env.PORT || 3000;
server.listen(app_port, function(){
console.log("Express server listening on port "+ app_port);
});
/**
* Socket.io
*/
var sio = io.listen(server);
sio.sockets.on('connection', function (socket) {
// temperature
setInterval(function () {
var val = (new Date).getTime();
socket.emit('new value', { val: "I'm a websocket message: "+val });
}, 2000);
});