Skip to content

Commit

Permalink
feat: support for absolute urls in plugin configuration
Browse files Browse the repository at this point in the history
BREAKING: adds a new environment variable RSD_REVERSE_PROXY url that is
required by the frontend container to construct the plugin base url when
running it in the same docker network.
  • Loading branch information
cmeessen committed Oct 7, 2024
1 parent 9f597f6 commit f201d6a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ POSTGREST_URL_EXTERNAL=http://localhost/api/v1
# .env.local: http://localhost/auth, .env: http://auth:7000
RSD_AUTH_URL=http://auth:7000

# RSD Reverse Proxy URL
# consumed by services: frontend
# .env.local: http://localhost, .env: http://nginx
RSD_REVERSE_PROXY_URL=http://nginx

# consumed by services: authentication
# If set to "dev", the first user to log in will become admin.
# Any other value doesn't activate this feature (and doesn't do anything).
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ services:
- RSD_AUTH_URL
- RSD_AUTH_PROVIDERS
- RSD_AUTH_COUPLE_PROVIDERS
- RSD_REVERSE_PROXY_URL
- MATOMO_URL
- MATOMO_ID
- SURFCONEXT_CLIENT_ID
Expand Down Expand Up @@ -149,7 +150,8 @@ services:
- database
- backend
- auth
# volumes:
volumes:
- ./frontend/public:/app/public
# - ./deployment/hmz/styles:/app/public/styles
# - ./deployment/hmz/data:/app/public/data
# - ./deployment/hmz/images:/app/public/images
Expand Down
16 changes: 14 additions & 2 deletions frontend/config/getPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@ import logger from '~/utils/logger'
import {createJsonHeaders} from '~/utils/fetchHelpers'
import {PluginConfig} from '~/config/RsdPluginContext'

async function getPlugin({pluginName,token}:{pluginName: string, token?: string}){
const url = `http://localhost/plugin/${pluginName}/api/config`

function getPluginBaseUrl(pluginName: string) {
if (/^(https?:\/\/)/.test(pluginName)) {
return pluginName
} else if (process.env.NODE_ENV === 'development') {
return `http://localhost/plugin/${pluginName}`
} else {
const baseUrl = process.env.RSD_REVERSE_PROXY_URL
return `${baseUrl}/plugin/${pluginName}`
}
}

async function getPlugin({pluginName, token}:{pluginName: string, token?: string}){
const url = getPluginBaseUrl(pluginName) + '/api/v1/config'
try {
const response = await fetch(url, {
headers: {
Expand Down

0 comments on commit f201d6a

Please sign in to comment.