From 3f1ca71a871037316f130f960108c689c36365ba Mon Sep 17 00:00:00 2001 From: Austin McGee <947888+amcgee@users.noreply.github.com> Date: Mon, 25 Mar 2024 11:58:36 +0100 Subject: [PATCH] feat: support core-injected base url (#836) * feat: support core-injected base url * style: format * feat: add base URL injection point to plugins * chore: comment for context * chore: fix comment --------- Co-authored-by: Kai Vandivier --- shell/public/index.html | 3 +++ shell/public/plugin.html | 2 ++ shell/src/App.js | 14 +++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/shell/public/index.html b/shell/public/index.html index a637da98c..5eff6b809 100644 --- a/shell/public/index.html +++ b/shell/public/index.html @@ -7,6 +7,9 @@ content="width=device-width, initial-scale=1, shrink-to-fit=no" /> + + + + Plugin diff --git a/shell/src/App.js b/shell/src/App.js index 9e8106ba4..4211f5361 100644 --- a/shell/src/App.js +++ b/shell/src/App.js @@ -9,6 +9,18 @@ const D2App = React.lazy(() => import(/*webpackChunkName: 'app'*/ './D2App/app') ) // Automatic bundle splitting! +// Injected by backend when serving index or plugin HTML +// https://github.com/dhis2/dhis2-core/pull/16703 +const getInjectedBaseUrl = () => { + const baseUrl = document + .querySelector('meta[name="dhis2-base-url"]') + ?.getAttribute('content') + if (baseUrl && baseUrl !== '__DHIS2_BASE_URL__') { + return baseUrl + } + return null +} + const parseRequiredProps = (propsEnvVariable) => { if (!propsEnvVariable || propsEnvVariable === '') { return [] @@ -22,7 +34,7 @@ const requiredPluginProps = parseRequiredProps( ) const appConfig = { - url: process.env.REACT_APP_DHIS2_BASE_URL, + url: getInjectedBaseUrl() || process.env.REACT_APP_DHIS2_BASE_URL, appName: process.env.REACT_APP_DHIS2_APP_NAME || '', appVersion: process.env.REACT_APP_DHIS2_APP_VERSION || '', apiVersion: parseInt(process.env.REACT_APP_DHIS2_API_VERSION),