diff --git a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js index 51d39db4947..9de67ea89e9 100644 --- a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js +++ b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js @@ -90,13 +90,13 @@ function body(buffer, bootstrap) { buffer.push(bootstrap.html.header); } -function bodyFooter(buffer, bootstrap) { +function bodyFooter(buffer, bootstrap, headers) { buffer.push(bootstrap.theme_html.body_tag); buffer.push(bootstrap.html.before_body_close); let v = crypto.randomUUID(); buffer.push(` - + `); } @@ -132,22 +132,22 @@ const BUILDERS = { "locale-script": localeScript, }; -function replaceIn(bootstrap, template, id) { +function replaceIn(bootstrap, template, id, headers) { let buffer = []; - BUILDERS[id](buffer, bootstrap); + BUILDERS[id](buffer, bootstrap, headers); let contents = buffer.filter((b) => b && b.length > 0).join("\n"); return template.replace(``, contents); } -function applyBootstrap(bootstrap, template) { +function applyBootstrap(bootstrap, template, headers) { Object.keys(BUILDERS).forEach((id) => { - template = replaceIn(bootstrap, template, id); + template = replaceIn(bootstrap, template, id, headers); }); return template; } -function buildFromBootstrap(assetPath, proxy, req) { +function buildFromBootstrap(assetPath, proxy, req, headers) { // eslint-disable-next-line return new Promise((resolve, reject) => { fs.readFile( @@ -156,7 +156,7 @@ function buildFromBootstrap(assetPath, proxy, req) { (err, template) => { getJSON(`${proxy}/bootstrap.json`, null, req.headers) .then((json) => { - resolve(applyBootstrap(json.bootstrap, template)); + resolve(applyBootstrap(json.bootstrap, template, headers)); }) .catch(() => { reject(`Could not get ${proxy}/bootstrap.json`); @@ -189,7 +189,12 @@ async function handleRequest(assetPath, proxy, req, res) { res.set(response.headers); if (response.headers["x-discourse-bootstrap-required"] === "true") { req.headers["X-Discourse-Asset-Path"] = req.path; - let json = await buildFromBootstrap(assetPath, proxy, req); + let json = await buildFromBootstrap( + assetPath, + proxy, + req, + response.headers + ); return res.send(json); } res.status(response.status);