From ff6d63a862e0afaed694625c0b9a327189653691 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Tue, 26 Feb 2019 11:52:23 +0200 Subject: [PATCH] Add index endpoint --- applications/highlight-termbin/index.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/applications/highlight-termbin/index.js b/applications/highlight-termbin/index.js index 92345b4..a371644 100644 --- a/applications/highlight-termbin/index.js +++ b/applications/highlight-termbin/index.js @@ -6,7 +6,8 @@ const fsp = fs.promises const router = express.Router() const cfgLoader = require(path.join('..', '..', 'config-loader'))(path.join(__dirname, 'config.json'), { root: path.join(process.cwd(), '..', 'fiche', 'code'), - style: 'tomorrow-night' + style: 'tomorrow-night', + index: 'index.html' }) async function init () { @@ -48,7 +49,6 @@ async function init () { '' + '' + '' + - '' + name + '' + '' + '' + '' + @@ -62,6 +62,21 @@ async function init () { res.set('Content-Type', 'application/xhtml+xml').send(payload) }) + router.get('/', (req, res, next) => { + if (!config.index) { + return next() + } + + let in = config.index + if (in.indexOf('/') !== 0) { + in = path.join(__dirname, in) + } else { + in = path.resolve(in) + } + + res.sendFile(in) + }) + return router }