From 75c2107b6c76951219ee601f8f03ded121b17bbf Mon Sep 17 00:00:00 2001 From: Don Benjamin Date: Mon, 15 Apr 2024 15:02:28 +0100 Subject: [PATCH] #365 Use relative urls in the browser to avoid needing to hardcode the domain name (#375) * #365 Updated documentation for changing ports. Updated the nuxt config to use separate internal and external api urls * #365 Switch to using relative urls --------- Co-authored-by: Julien Nahum --- client/.env.docker | 5 +++-- client/composables/useOpnApi.js | 2 +- client/runtimeConfig.js | 1 + docker/nuxt-wrapper.sh | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/.env.docker b/client/.env.docker index 3b55165b..ced6ff23 100644 --- a/client/.env.docker +++ b/client/.env.docker @@ -1,6 +1,7 @@ NUXT_LOG_LEVEL= -NUXT_PUBLIC_APP_URL=http://localhost/ -NUXT_PUBLIC_API_BASE=http://localhost/api +NUXT_PUBLIC_APP_URL=/ +NUXT_PUBLIC_API_BASE=/api +NUXT_PRIVATE_API_BASE=http://localhost/api NUXT_PUBLIC_AI_FEATURES_ENABLED=false NUXT_PUBLIC_AMPLITUDE_CODE= NUXT_PUBLIC_CRISP_WEBSITE_ID= diff --git a/client/composables/useOpnApi.js b/client/composables/useOpnApi.js index 7f1ff8ff..c278a289 100644 --- a/client/composables/useOpnApi.js +++ b/client/composables/useOpnApi.js @@ -47,7 +47,7 @@ export function getOpnRequestsOptions(request, opts) { addPasswordToFormRequest(request, opts) addCustomDomainHeader(request, opts) - if (!opts.baseURL) opts.baseURL = config.public.apiBase + if (!opts.baseURL) opts.baseURL = config.privateApiBase || config.public.apiBase return { async onResponseError({response}) { diff --git a/client/runtimeConfig.js b/client/runtimeConfig.js index 80cbc25f..eb1414a6 100644 --- a/client/runtimeConfig.js +++ b/client/runtimeConfig.js @@ -25,4 +25,5 @@ export default { * Used to authenticate that the requests are coming from the server - not from a client. */ apiSecret: process.env.NUXT_API_SECRET || '', + privateApiBase: process.env.NUXT_PRIVATE_API_BASE || null, } diff --git a/docker/nuxt-wrapper.sh b/docker/nuxt-wrapper.sh index 3b7f2084..8eb246c9 100644 --- a/docker/nuxt-wrapper.sh +++ b/docker/nuxt-wrapper.sh @@ -10,6 +10,8 @@ nvm use 20 cd /app/nuxt/server/ +export NUXT_PRIVATE_API_BASE=http://localhost/api + echo + . /app/client/.env [ -f /app/client/.env ] && . /app/client/.env || echo "Environment file missing!"