Prevent invalid config injected in HTML

This commit is contained in:
Chocobozzz 2023-02-09 08:59:44 +01:00
parent 2898445c53
commit b9200c6411
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 10 additions and 4 deletions

View File

@ -86,7 +86,8 @@ app.use('/*', async function (req, res) {
: '' : ''
// Stringify the JSON object, and then stringify the string object so we can inject it into the HTML // Stringify the JSON object, and then stringify the string object so we can inject it into the HTML
const serverConfigString = JSON.stringify(JSON.stringify(getConfig())) const config = getConfig()
const serverConfigString = JSON.stringify(JSON.stringify(config))
const configJS = `<script type="application/javascript">window.PeerTubeServerConfig = ${serverConfigString}</script>` const configJS = `<script type="application/javascript">window.PeerTubeServerConfig = ${serverConfigString}</script>`
const tags = ` const tags = `
@ -113,10 +114,15 @@ app.use('/*', async function (req, res) {
const buffer = await readFile(join(__dirname, '../client/dist/index.html')) const buffer = await readFile(join(__dirname, '../client/dist/index.html'))
indexHTML = buffer.toString() let html = buffer.toString()
indexHTML = indexHTML.replace('</head>', tags + '</head>') html = html.replace('</head>', tags + '</head>')
return res.send(indexHTML) // Prevent caching a not ready yet configuration (because the indexer did not have time to run)
if (config.indexedHostsCount !== 0) {
indexHTML = html
}
return res.send(html)
}) })
// ----------- Errors ----------- // ----------- Errors -----------