Skip to content

Commit

Permalink
Pre-render changelog on the server side
Browse files Browse the repository at this point in the history
To improve performance, render the changelog when starting the server
instead of doing it whenever the endpoint is reached.
  • Loading branch information
psvenk committed Feb 1, 2021
1 parent 4c7d072 commit 0e677d0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const marked = require("marked");
// Get Aspine version number without leading 'v'
const version = child_process.execSync('git describe')
.toString().trim().match(/^v?(.*)/)[1];
const changelog = marked(
fs.readFileSync(__dirname + '/CHANGELOG.md').toString()
);

program
.version(version)
Expand Down Expand Up @@ -158,12 +161,8 @@ app.use('/fonts/material-icons/iconfont', express.static(
// Endpoint to expose version number to client
app.get('/version', (req, res) => res.send(version));



app.get('/updates', async (req, res) => {
const changelog = await fs.promises.readFile(__dirname + '/CHANGELOG.md');
res.send(marked(changelog.toString()));
});
// Endpoint to expose rendered changelog to client
app.get('/updates', (req, res) => res.send(changelog));

app.use(function(req, res, next) { // enable cors
res.header("Access-Control-Allow-Origin", "*");
Expand Down

0 comments on commit 0e677d0

Please sign in to comment.