-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
49 lines (37 loc) · 1.08 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
require('dotenv').config();
const {
PORT,
} = process.env;
const debug = require('debug')('clownfish');
const express = require('express');
const sysinfo = require('./lib/sysinfo');
const db = require('./lib/db');
const auth = require('./lib/auth');
const app = express();
app.set('view engine', 'pug');
app.use(require('body-parser').json());
app.use(require('body-parser').urlencoded({ extended: true }));
// this is auth0
app.use(auth);
app.get('/add-server', (req, res) => {
res.render('add-server');
});
app.get('/', (req, res, next) => {
// req.isAuthenticated is provided from the auth router
debug('is authenticated:', req.oidc.isAuthenticated());
try {
const info = sysinfo();
const logs = db
.prepare('SELECT * FROM inbox ORDER BY timestamp DESC LIMIT 10;')
.all();
res.render('index', {
info, title: 'Clownfish', subtitle: 'by IMA World Health', logs,
});
} catch (e) {
debug('An error occurred: %o', e);
next(e);
}
});
// require the imap listener
require('./lib/imap');
app.listen(PORT, () => debug(`listening on port: ${PORT}.`));