-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (23 loc) · 919 Bytes
/
app.js
File metadata and controls
30 lines (23 loc) · 919 Bytes
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
const express = require('express');
const ReportGenerator = require('lighthouse/lighthouse-core/report/report-generator');
const Report = require('./models/Report');
const setupMongoDB = require('./db/config');
const setupReportCron = require('./cron/runReport');
const app = express();
const PORT = process.env.PORT || 3001;
setupMongoDB();
setupReportCron('https://gupy.gupy.io/candidates');
app.set('views', './views');
app.set('view engine', 'pug');
app.get('/reports', async (req, res) => {
const reports = (await Report.find().sort({ createdAt: 'asc' })) || [];
res.render('index', { reports })
});
app.get('/reports/:reportId', async (req, res) => {
const report = (await Report.findOne({ _id: req.params.reportId })) || {};
const html = ReportGenerator.generateReport(JSON.parse(report.json), 'html');
res.send(html);
});
app.listen(PORT, () => {
console.log(`Magic happens at ${PORT}`);
});