From 0e677d0e18baafaf0a9e9d4d1496ba25003d009b Mon Sep 17 00:00:00 2001 From: psvenk <45520974+psvenk@users.noreply.github.com> Date: Sun, 31 Jan 2021 21:16:14 -0500 Subject: [PATCH] Pre-render changelog on the server side To improve performance, render the changelog when starting the server instead of doing it whenever the endpoint is reached. --- serve.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/serve.js b/serve.js index b9156070..56ca0eff 100644 --- a/serve.js +++ b/serve.js @@ -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) @@ -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", "*");