From ed591ff72d435afc52099704a9b6052feef7c19f Mon Sep 17 00:00:00 2001 From: Cogent Apps Date: Mon, 17 Apr 2023 18:00:07 +0000 Subject: [PATCH] allow head customization --- server/src/index.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/server/src/index.ts b/server/src/index.ts index a1a21044..f741795c 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -103,19 +103,28 @@ export default class ChatServer { } if (fs.existsSync('public')) { - const match = ``; - const replace = ``; + const match = /`; const indexFilename = "public/index.html"; - const indexSource = fs.readFileSync(indexFilename, 'utf8'); + let indexSource = fs.readFileSync(indexFilename, 'utf8'); - fs.writeFileSync(indexFilename, indexSource.replace(match, replace)); + indexSource = indexSource.replace(match, replace); + + if (fs.existsSync('./data/head.html')) { + const head = fs.readFileSync('./data/head.html').toString(); + indexSource = indexSource.replace(' ', ` ${head} `); + } + + this.app.get('/', (req, res) => { + res.send(indexSource); + }); this.app.use(express.static('public')); // serve index.html for all other routes this.app.get('*', (req, res) => { - res.sendFile('public/index.html', { root: path.resolve(__dirname, '..') }); + res.send(indexSource); }); }