-
Notifications
You must be signed in to change notification settings - Fork 15
/
server.js
38 lines (32 loc) · 1.12 KB
/
server.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
const express = require('express');
const cors = require('cors');
const mds = require('markdown-serve');
const path = require('path');
const app = express();
app.use(cors());
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log('We are live on port ' + port);
});
// markdown and static content serving
app.set('views', path.resolve(__dirname, './markdown-layouts'));
app.set('view engine', 'pug');
app.use(express.static(path.resolve(__dirname, './markdown-layouts')));
const mdServer = new mds.MarkdownServer(path.resolve(__dirname, ''));
mdServer.resolverOptions.defaultPageName = 'README';
app.get(['/', '/README'], (req, res, next) => {
mdServer.get(req.path, (err, result) => {
if (err) {
console.error(err);
return next();
}
res.render('layout', {markdownFile: result});
});
});
// import all of the 'routes' JS files
require('./app/routes')(app);
// eslint-disable-next-line no-unused-vars
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Error - please try again or raise an issue at https://github.com/AdoptOpenJDK/openjdk-api/issues');
});