diff --git a/common/app/common/CommercialBundle.scala b/common/app/common/CommercialBundle.scala index a129814f7af..acc5bee6d44 100644 --- a/common/app/common/CommercialBundle.scala +++ b/common/app/common/CommercialBundle.scala @@ -10,30 +10,32 @@ object CommercialBundle { private lazy val parameterStore = new ParameterStore(Environment.awsRegion) - private var cachedBundlePath: String = - "test_commercial_bundles/" + bundlePathParameterValue - private var cachedTimestamp: Instant = Instant.now() private val cacheDuration: FiniteDuration = 1.minute + private val stage = Environment.stage + + private var cachedBundlePath: String = bundlePathFromParameterStore + private var cachedTimestamp: Instant = Instant.now() - private val assetHost = Configuration.assets.path + // when running locally Configuration.assets.path is set to "assets/" to serve local assets, but the commercial bundle no longer lives there, so we need to override it + private val basePath = + if (stage.equalsIgnoreCase("dev")) "https://assets-code.guim.co.uk/" else Configuration.assets.path - private def bundlePathParameterValue: String = { - if (Environment.stage == "CODE") + private def bundlePathFromParameterStore: String = { + if (stage == "CODE") parameterStore.get("/frontend/CODE/commercial.bundlePath") else + // for PROD and DEV to use the same bundle path parameterStore.get("/frontend/commercial.bundlePath") } - private def updateBundlePath(): Unit = { - cachedBundlePath = "test_commercial_bundles/" + bundlePathParameterValue - cachedTimestamp = Instant.now() - } - private def bundlePath: String = { - if (Instant.now().isAfter(cachedTimestamp.plus(cacheDuration.toMillis))) updateBundlePath() + if (Instant.now().isAfter(cachedTimestamp.plus(cacheDuration.toMillis))) { + cachedBundlePath = bundlePathFromParameterStore + cachedTimestamp = Instant.now() + } cachedBundlePath } - def getBundleUrl: String = s"$assetHost$bundlePath" + def bundleUrl: String = s"$basePath$bundlePath" } diff --git a/common/app/views/support/JavaScriptPage.scala b/common/app/views/support/JavaScriptPage.scala index ce64a5bdd39..0ef5a23d380 100644 --- a/common/app/views/support/JavaScriptPage.scala +++ b/common/app/views/support/JavaScriptPage.scala @@ -74,7 +74,7 @@ object JavaScriptPage { val commercialBundleUrl = if (ActiveExperiments.isParticipating(CommercialBundleUpdater)(request)) - JsString(CommercialBundle.getBundleUrl) + JsString(CommercialBundle.bundleUrl) else JsString( Configuration.commercial.overrideCommercialBundleUrl