From f201d6a993df8229fb86faea14998a78a52026a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mee=C3=9Fen?= <14222414+cmeessen@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:07:35 +0200 Subject: [PATCH] feat: support for absolute urls in plugin configuration 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. --- .env.example | 5 +++++ docker-compose.yml | 4 +++- frontend/config/getPlugins.ts | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index f9327652a..ec0143878 100644 --- a/.env.example +++ b/.env.example @@ -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). diff --git a/docker-compose.yml b/docker-compose.yml index 5d6d5dd17..1965f0ff1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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 diff --git a/frontend/config/getPlugins.ts b/frontend/config/getPlugins.ts index 8789d1cc7..187df5f87 100644 --- a/frontend/config/getPlugins.ts +++ b/frontend/config/getPlugins.ts @@ -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: {