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); }); }