From 2e428c8ef3472ce1c282339072470bfeefc9065e Mon Sep 17 00:00:00 2001 From: Nathan Muir Date: Tue, 30 Oct 2018 17:39:29 +1000 Subject: [PATCH 1/2] 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. --- packages/webapp/webapp_server.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/webapp/webapp_server.js b/packages/webapp/webapp_server.js index 1fa2daa65c..ccbfb6081f 100644 --- a/packages/webapp/webapp_server.js +++ b/packages/webapp/webapp_server.js @@ -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(); From 40ac2de412dfe4d3e11ded0738fe88055183c449 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Wed, 21 Nov 2018 11:34:01 -0500 Subject: [PATCH 2/2] Use object ...spread syntax rather than _.extend. --- packages/webapp/webapp_server.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/webapp/webapp_server.js b/packages/webapp/webapp_server.js index ccbfb6081f..1037d44aa7 100644 --- a/packages/webapp/webapp_server.js +++ b/packages/webapp/webapp_server.js @@ -798,11 +798,11 @@ function runWebAppServer() { program.manifest, additionalOptions, ); - // we need the runtime config w/ overrides for meteor_runtime_config.js - program.meteorRuntimeConfig = JSON.stringify(_.extend( - _.clone(__meteor_runtime_config__), - additionalOptions.runtimeConfigOverrides || {} - )); + // We need the runtime config with overrides for meteor_runtime_config.js: + program.meteorRuntimeConfig = JSON.stringify({ + ...__meteor_runtime_config__, + ...(additionalOptions.runtimeConfigOverrides || null), + }); program.refreshableAssets = baseData.css.map(file => ({ url: bundledJsCssUrlRewriteHook(file.url), }));