webapp: add runtime config overrides when inline scripts are disabled

When generating boilerplate, meteor runtime config includes additional
options based on the arch.

However, these additional options were not present when generating
the response to `/meteor_runtime_config.js`, which is used when
inline scripts are disabled.

This change fixes Meteor.isModern in those circumstances.
This commit is contained in:
Nathan Muir
2018-10-30 17:39:29 +10:00
parent 8f86f19cd0
commit 2e428c8ef3

View File

@@ -386,12 +386,7 @@ WebAppInternals.staticFilesMiddleware = async function (
res.end();
};
if (pathname === "/meteor_runtime_config.js" &&
! WebAppInternals.inlineScriptsAllowed()) {
serveStaticJs("__meteor_runtime_config__ = " +
JSON.stringify(__meteor_runtime_config__) + ";");
return;
} else if (_.has(additionalStaticJs, pathname) &&
if (_.has(additionalStaticJs, pathname) &&
! WebAppInternals.inlineScriptsAllowed()) {
serveStaticJs(additionalStaticJs[pathname]);
return;
@@ -404,7 +399,14 @@ WebAppInternals.staticFilesMiddleware = async function (
// If pauseClient(arch) has been called, program.paused will be a
// Promise that will be resolved when the program is unpaused.
await WebApp.clientPrograms[arch].paused;
const program = WebApp.clientPrograms[arch];
await program.paused;
if (path === "/meteor_runtime_config.js" &&
! WebAppInternals.inlineScriptsAllowed()) {
serveStaticJs(`__meteor_runtime_config__ = ${program.meteorRuntimeConfig};`);
return;
}
const info = getStaticFileInfo(pathname, path, arch);
if (! info) {
@@ -789,13 +791,18 @@ function runWebAppServer() {
function generateBoilerplateForArch(arch) {
const program = WebApp.clientPrograms[arch];
const additionalOptions = defaultOptionsForArch[arch] || {};
const { baseData } = boilerplateByArch[arch] =
WebAppInternals.generateBoilerplateInstance(
arch,
program.manifest,
defaultOptionsForArch[arch],
additionalOptions,
);
// we need the runtime config w/ overrides for meteor_runtime_config.js
program.meteorRuntimeConfig = JSON.stringify(_.extend(
_.clone(__meteor_runtime_config__),
additionalOptions.runtimeConfigOverrides || {}
));
program.refreshableAssets = baseData.css.map(file => ({
url: bundledJsCssUrlRewriteHook(file.url),
}));
@@ -835,7 +842,7 @@ function runWebAppServer() {
// Do this before the next middleware destroys req.url if a path prefix
// is set to close #10111.
app.use(query());
function getPathParts(path) {
const parts = path.split("/");
while (parts[0] === "") parts.shift();