-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
101 lines (73 loc) · 2.05 KB
/
app.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var express = require('express');
var stylus = require('stylus');
var nib = require('nib');
var morgan = require('morgan');
var parking = require('./parking.js');
var tampere = require('./tampere.js');
var digitraffic = require('./digitraffic.js');
function compile(str, path) {
return stylus(str)
.set('filename', path)
.use(nib());
}
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
if (app.get('env') === 'development') {
app.locals.pretty = true;
}
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(morgan('dev'));
app.use(stylus.middleware(
{ src: __dirname + '/public'
, compile: compile
}
));
app.use(express.static(__dirname + '/public'));
app.get('/', function (req, res) {
res.render('geostat',
{title: 'Tamperelaisen paikkatilasto'});
});
app.get('/charts', function (req, res) {
parking.showParkingCharts(req, res);
});
app.get('/3d', function (req, res) {
res.render('3dmap',
{title: 'Tampereen korkeusmalli'});
});
app.get('/parkki', function (req, res) {
parking.showParkingMap(req, res);
});
app.get('/about', function (req, res) {
res.render('about',
{title: 'Tamperelaisen paikkatilasto'});
});
app.get('/heat', function (req, res) {
res.render('heat',
{title: 'Heatmap kokeilu'});
});
app.get('/digitraffic', function (req, res) {
digitraffic.showCategories(req, res);
});
app.get('/roadweather.json', function (req, res) {
digitraffic.roadweather(req, res);
});
app.get('/tredata.json', function (req, res) {
tampere.getTreJSONData(req, res);
});
io.on('connection', function(socket){
console.log('a client connected');
socket.on('disconnect', function(){
console.log('a client disconnected');
});
});
app.set('port', (process.env.PORT || 3000));
http.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'))
});
setInterval(updateClientData, 300000);
//setInterval(updateClientData, 10000);
function updateClientData() {
digitraffic.updateClientData(io);
}