Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support core-injected base url #836

Merged
merged 6 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions shell/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#ffffff" />

<!-- Injection point for base URL from backend -->
<meta name="dhis2-base-url" content="__DHIS2_BASE_URL__" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
Expand Down
2 changes: 2 additions & 0 deletions shell/public/plugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<!-- Injection point for base URL from backend -->
<meta name="dhis2-base-url" content="__DHIS2_BASE_URL__" />
<title>Plugin</title>
</head>
<body>
Expand Down
14 changes: 13 additions & 1 deletion shell/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand All @@ -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),
Expand Down
Loading