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) {
|
function extractPreloadJson(html) {
|
||||||
const dom = new JSDOM(html);
|
const dom = new JSDOM(html);
|
||||||
return dom.window.document.querySelector("#data-preloaded")?.dataset
|
const dataElement = dom.window.document.querySelector("#data-preloaded");
|
||||||
?.preloaded;
|
|
||||||
|
if (!dataElement || !dataElement.dataset) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataElement.dataset.preloaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function applyBootstrap(bootstrap, template, response, baseURL, preload) {
|
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);
|
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 responseText = await response.text();
|
||||||
const preload = isHTML ? extractPreloadJson(responseText) : null;
|
|
||||||
|
|
||||||
if (preload) {
|
if (contentType && contentType.startsWith("text/html")) {
|
||||||
const html = await buildFromBootstrap(
|
const html = await buildFromBootstrap(
|
||||||
proxy,
|
proxy,
|
||||||
baseURL,
|
baseURL,
|
||||||
req,
|
req,
|
||||||
response,
|
response,
|
||||||
preload
|
extractPreloadJson(responseText)
|
||||||
);
|
);
|
||||||
res.set("content-type", "text/html");
|
res.set("content-type", "text/html");
|
||||||
res.send(html);
|
res.send(html);
|
||||||
|
|
Loading…
Reference in New Issue