This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
forked from davefp/handsome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
68 lines (56 loc) · 1.86 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
var express = require('express');
var exphbs = require('express-handlebars');
var app = express();
var moment = require('moment');
var config = require(__dirname + '/config.js');
var redis = config.getRedisClient();
const path = require('path');
app.engine('hbs', exphbs({defaultLayout: 'index', extname: '.hbs', layoutsDir: 'views/'}));
app.set('view engine', 'hbs');
app.set('port', (process.env.PORT || 3000));
app.get('/', function (req, res) {
res.render('index', {name: 'index'});
});
app.get('/:dashboard', function(req, res) {
res.render('index', {name: req.params.dashboard, layout: false});
});
app.get('/widgets/:widget.json', function(req, res) {
redis.get(req.params.widget, function(err, reply) {
if(err || reply === null) {
res.json({'error': err});
} else {
console.log("json");
console.log(reply);
var reply_json = JSON.parse(reply);
var next_time = moment(reply_json.next_time);
delete reply_json.next_time;
var now = moment();
if (now.isBefore(next_time)) {
reply_json.updates_in_millis = moment.duration(next_time.diff(now)).asMilliseconds();
} else {
reply_json.updates_in_millis = 5000;
}
res.json(reply_json);
}
})
});
app.listen(app.get('port'), function () {
console.log("Up and running on port " + app.get('port'));
});
// Serve our bundle
if(process.env.NODE_ENV === 'production') {
// serve the contents of the build folder
app.use("/assets", express.static('build'));
} else {
// serve using webpack middleware
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var config = require('./webpack.config');
var compiler = webpack(config);
app.use(webpackDevMiddleware(compiler, {
publicPath: '/assets/',
stats: {colors: true}
}));
}
// load our jobs
require(__dirname + '/jobs.js');