-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (30 loc) · 956 Bytes
/
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
import express from 'express';
import fs from 'fs';
import open from 'open';
import path from 'path';
import { bioboxDir, getNavElement, writeFile } from './files.js';
import { fetchRelevantArticleAsHTML } from './biobox.js';
const app = express();
app.set('view engine', 'ejs')
app.get('/', async (req, res) => {
const article = await fetchRelevantArticleAsHTML();
const nav = getNavElement();
writeFile(article);
res.render('./index', { article, nav })
});
app.get('/:filename', async (req, res) => {
const filename = req.params.filename;
try {
const filePath = path.join(bioboxDir, filename);
const article = fs.readFileSync(filePath, 'utf-8');
const nav = getNavElement();
res.render('./index', { article, nav })
}
catch (err) {
res.status(404).send('File not found: ' + err);
}
})
app.use('favicon.png', express.static('./favicon.png'));
app.listen(3000, () => {
// open('http://localhost:3000')
});