-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 1.64 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
const express = require('express');
const app = express();
const port = 3000 || process.env.PORT;
const db = require('./services/db');
const findingsRouter = require('./routes/findings');
const holyGrailRouter = require('./routes/holy_grail_findings');
const reportRouter = require('./routes/report_router')
const formidableMiddleware = require('express-formidable');
app.use(function (req, res, next) {
const latest_rune = db.instance.prepare(`SELECT player_name, rune_name, finding_date as 'finding_date'
FROM finding JOIN rune ON rune.rune_id = finding.rune_id JOIN player ON player.player_id = finding.player_id
ORDER BY datetime(finding_date) DESC LIMIT 1`).all([]);
const latest_grail = db.instance.prepare(`SELECT player_name, item_name, finding_date as 'finding_date'
FROM holy_grail_item_finding JOIN holy_grail_item ON holy_grail_item.holy_grail_item_id = holy_grail_item_finding.holy_grail_item_id JOIN player ON player.player_id = holy_grail_item_finding.player_id
ORDER BY datetime(finding_date) DESC LIMIT 1`).all([]);
res.locals.latest_rune = latest_rune[0];
res.locals.latest_grail = latest_grail[0];
next();
});
app.use(formidableMiddleware());
app.use(express.static('css'));
app.use(express.static('images'));
app.use(express.static('fonts'));
app.use(express.json());
app.set('view engine', 'pug');
app.use('/', reportRouter)
app.use('/stats', findingsRouter);
app.use('/findings', findingsRouter);
app.use('/holy_grail_stats', holyGrailRouter);
app.use('/holy_grail_findings', holyGrailRouter);
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});