Add index endpoint

This commit is contained in:
Evert Prants 2019-02-26 11:52:23 +02:00
parent cc29fd2931
commit ff6d63a862
Signed by: evert
GPG Key ID: 1688DA83D222D0B5

View File

@ -6,7 +6,8 @@ const fsp = fs.promises
const router = express.Router() const router = express.Router()
const cfgLoader = require(path.join('..', '..', 'config-loader'))(path.join(__dirname, 'config.json'), { const cfgLoader = require(path.join('..', '..', 'config-loader'))(path.join(__dirname, 'config.json'), {
root: path.join(process.cwd(), '..', 'fiche', 'code'), root: path.join(process.cwd(), '..', 'fiche', 'code'),
style: 'tomorrow-night' style: 'tomorrow-night',
index: 'index.html'
}) })
async function init () { async function init () {
@ -48,7 +49,6 @@ async function init () {
'<?xml version="1.0" encoding="UTF-8"?>' + '<?xml version="1.0" encoding="UTF-8"?>' +
'<html xmlns="http://www.w3.org/1999/xhtml" class="hljs">' + '<html xmlns="http://www.w3.org/1999/xhtml" class="hljs">' +
'<head>' + '<head>' +
'<title>' + name + '</title>' +
'<link rel="stylesheet" href="/assets/css/t.css" />' + '<link rel="stylesheet" href="/assets/css/t.css" />' +
'<link rel="stylesheet" href="/assets/css/t-styles/' + config.style + '.css" />' + '<link rel="stylesheet" href="/assets/css/t-styles/' + config.style + '.css" />' +
'<script src="/assets/js/highlight.min.js"></script>' + '<script src="/assets/js/highlight.min.js"></script>' +
@ -62,6 +62,21 @@ async function init () {
res.set('Content-Type', 'application/xhtml+xml').send(payload) 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 return router
} }