-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (52 loc) · 1.53 KB
/
index.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
const express = require('express');
const hbs = require('express-hbs');
const arteDB = require('./src/arteDB');
const app = express();
// I am guilty of stackoverflow ;) http://stackoverflow.com/a/20429914
function nocache(req, res, next) {
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
next();
}
app.get('/', function (req, res) {
const accept = req.acceptsLanguages(['fr', 'de']);
if (accept === 'fr') {
res.redirect('/fr');
} else {
res.redirect('/de');
}
});
app.get('/:language', nocache, function (req, res) {
if (!arteDB.dataLoaded) {
res.render('starting');
return;
}
const language = req.params.language;
if (language === 'de' || language === 'fr') {
res.render('index', {
title: 'Arte plus7 viewer - Unofficial',
shows: arteDB.tvGuideData[language],
channels: arteDB.channelData[language]
});
} else {
res.send('No such language.');
}
});
const port = process.env.PORT || 5000;
const server = app.listen(port, function () {
const host = server.address().address;
console.log('Example app listening at http://%s:%s', host, port);
});
app.use(express.static('public'));
app.engine('hbs', hbs.express4({
partialsDir: `${__dirname}/views/partials`
}));
app.set('view engine', 'hbs');
app.set('views', `${__dirname}/views`);
hbs.registerHelper('ifFirstSix', function(index, options) {
if (index < 6) {
return options.fn(this);
}
return options.inverse(this);
});