-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (34 loc) · 1.04 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
const app = require('express')();
const nunjucks = require('nunjucks');
const cacheProvider = require('./hue/models/cache');
const bodyParser = require('body-parser');
const hueScheduler = require('./hue/controllers/scheduler');
const server = app.listen(8000, () => {
const port = server.address().port;
console.log('Listening at port %s', port);
});
// Start cache instance
cacheProvider.init();
// Set up cron-like Hue schedule on first launch
hueScheduler();
// Set up Nunjucks for Groceries
nunjucks.configure('/', {
autoescape: true,
express: app
});
// ====================================
// Middleware
// ====================================
app.use(bodyParser.json());
// ====================================
// Routes
// ====================================
app.get('/', (req, res) => {
res.send('Hello world!');
});
app.use('/hue', require('./hue/controllers'));
// Redirect to avoid relative path errors in index.html
app.all(/^\/groceries$/, (req, res) => {
res.redirect('/groceries/');
});
app.use('/groceries/', require('./groceries'));