mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:19:27 +08:00
DEV: Don't use ?.
in bootstrap-json (#15162)
That code is not transpiled, so it doesn't work on older node versions.
This commit is contained in:
parent
bd140948e3
commit
1b3d124a4e
|
@ -171,8 +171,13 @@ function replaceIn(bootstrap, template, id, headers, baseURL) {
|
|||
|
||||
function extractPreloadJson(html) {
|
||||
const dom = new JSDOM(html);
|
||||
return dom.window.document.querySelector("#data-preloaded")?.dataset
|
||||
?.preloaded;
|
||||
const dataElement = dom.window.document.querySelector("#data-preloaded");
|
||||
|
||||
if (!dataElement || !dataElement.dataset) {
|
||||
return;
|
||||
}
|
||||
|
||||
return dataElement.dataset.preloaded;
|
||||
}
|
||||
|
||||
async function applyBootstrap(bootstrap, template, response, baseURL, preload) {
|
||||
|
@ -264,17 +269,16 @@ async function handleRequest(proxy, baseURL, req, res) {
|
|||
res.set("content-security-policy", newCSP);
|
||||
}
|
||||
|
||||
const isHTML = response.headers.get("content-type")?.startsWith("text/html");
|
||||
const contentType = response.headers.get("content-type");
|
||||
const responseText = await response.text();
|
||||
const preload = isHTML ? extractPreloadJson(responseText) : null;
|
||||
|
||||
if (preload) {
|
||||
if (contentType && contentType.startsWith("text/html")) {
|
||||
const html = await buildFromBootstrap(
|
||||
proxy,
|
||||
baseURL,
|
||||
req,
|
||||
response,
|
||||
preload
|
||||
extractPreloadJson(responseText)
|
||||
);
|
||||
res.set("content-type", "text/html");
|
||||
res.send(html);
|
||||
|
|
Loading…
Reference in New Issue
Block a user