From 09c3da2be19be29dff4d1e02c150b7b24cf0d67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Tue, 21 May 2024 17:50:29 +0200 Subject: [PATCH] fix webApp.addRuntimeConfigHook --- packages/webapp/webapp_server.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/webapp/webapp_server.js b/packages/webapp/webapp_server.js index a616f7faf6..a2ec29bacd 100644 --- a/packages/webapp/webapp_server.js +++ b/packages/webapp/webapp_server.js @@ -428,21 +428,23 @@ WebApp.addRuntimeConfigHook = function(callback) { return runtimeConfig.hooks.register(callback); }; -function getBoilerplateAsync(request, arch) { +async function getBoilerplateAsync(request, arch) { let boilerplate = boilerplateByArch[arch]; - runtimeConfig.hooks.forEach(hook => { - const meteorRuntimeConfig = hook({ - arch, - request, - encodedCurrentConfig: boilerplate.baseData.meteorRuntimeConfig, - updated: runtimeConfig.isUpdatedByArch[arch], - }); - if (!meteorRuntimeConfig) return true; - boilerplate.baseData = Object.assign({}, boilerplate.baseData, { - meteorRuntimeConfig, - }); - return true; - }); + if (Array.isArray(runtimeConfig.hooks)) { + for (const hook of runtimeConfig.hooks) { + // Await the hook call since it is now async + const meteorRuntimeConfig = await hook({ + arch, + request, + encodedCurrentConfig: boilerplate.baseData.meteorRuntimeConfig, + updated: runtimeConfig.isUpdatedByArch[arch], + }); + if (!meteorRuntimeConfig) continue; + boilerplate.baseData = Object.assign({}, boilerplate.baseData, { + meteorRuntimeConfig, + }); + } + } runtimeConfig.isUpdatedByArch[arch] = false; const data = Object.assign( {}, @@ -1516,4 +1518,3 @@ WebAppInternals.getBoilerplate = getBoilerplate; WebAppInternals.additionalStaticJs = additionalStaticJs; await runWebAppServer(); -