A couple important Ember CLI fixes (#12345)

* FIX: Error related to sending headers twice

* FIX: Insert correct bootstrap contents in test runner html and boot
This commit is contained in:
Robin Ward 2021-03-11 14:40:25 -05:00 committed by GitHub
parent 3eb769d03b
commit 7036346965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 7 deletions

View File

@ -27,6 +27,15 @@
<div id='offscreen-content'>
</div>
<script>
document.addEventListener("discourse-booted", (e) => {
const config = e.detail;
const app = require(`${config.modulePrefix}/app`)["default"].create(
config
);
app.start();
});
</script>
{{bootstrap-content-for "hidden-login-form"}}
{{bootstrap-content-for "preloaded"}}

View File

@ -20,6 +20,25 @@ function htmlTag(buffer, bootstrap) {
buffer.push(`<html lang="${bootstrap.html_lang}"${classList}>`);
}
function bareStylesheets(buffer, bootstrap) {
(bootstrap.stylesheets || []).forEach((s) => {
if (s.theme_id) {
return;
}
let attrs = [];
if (s.media) {
attrs.push(`media="${s.media}"`);
}
if (s.target) {
attrs.push(`data-target="${s.target}"`);
}
let link = `<link rel="stylesheet" type="text/css" href="${
s.href
}" ${attrs.join(" ")}></script>\n`;
buffer.push(link);
});
}
function head(buffer, bootstrap) {
if (bootstrap.csrf_token) {
buffer.push(`<meta name="csrf-param" buffer="authenticity_token">`);
@ -72,9 +91,13 @@ function head(buffer, bootstrap) {
buffer.push(bootstrap.html.before_head_close);
}
function localeScript(buffer, bootstrap) {
buffer.push(`<script src="${bootstrap.locale_script}"></script>`);
}
function beforeScriptLoad(buffer, bootstrap) {
buffer.push(bootstrap.html.before_script_load);
buffer.push(`<script src="${bootstrap.locale_script}"></script>`);
localeScript(buffer, bootstrap);
(bootstrap.extra_locales || []).forEach((l) =>
buffer.push(`<script src="${l}"></script>`)
);
@ -119,6 +142,8 @@ const BUILDERS = {
"hidden-login-form": hiddenLoginForm,
preloaded: preloaded,
"body-footer": bodyFooter,
"locale-script": localeScript,
"bare-stylesheets": bareStylesheets,
};
function replaceIn(bootstrap, template, id) {
@ -136,11 +161,11 @@ function applyBootstrap(bootstrap, template) {
return template;
}
function decorateIndex(baseUrl, headers) {
function decorateIndex(assetPath, baseUrl, headers) {
// eslint-disable-next-line
return new Promise((resolve, reject) => {
fs.readFile(
path.join(process.cwd(), "dist", "index.html"),
path.join(process.cwd(), "dist", assetPath),
"utf8",
(err, template) => {
getJSON(`${baseUrl}/bootstrap.json`, null, headers)
@ -190,9 +215,13 @@ module.exports = {
}
if (!isFile) {
assetPath = "index.html";
}
if (assetPath.endsWith("index.html")) {
let template;
try {
template = await decorateIndex(proxy, req.headers);
template = await decorateIndex(assetPath, proxy, req.headers);
} catch (e) {
template = `
<html>
@ -201,7 +230,7 @@ module.exports = {
</html>
`;
}
res.send(template);
return res.send(template);
}
}
} finally {

View File

@ -177,6 +177,6 @@
const config = JSON.parse(
decodeURIComponent(element.getAttribute("content"))
);
const app = require(`${config.modulePrefix}/app`)["default"].create(config);
app.start();
const event = new CustomEvent("discourse-booted", { detail: config });
document.dispatchEvent(event);
})();

View File

@ -27,6 +27,8 @@
}
</style>
{{bootstrap-content-for "locale-script"}}
{{bootstrap-content-for "bare-stylesheets"}}
</head>
<body>
{{content-for "body"}}