Skip to content

Commit

Permalink
Apply patch to react app to manage api prefix dynamically.
Browse files Browse the repository at this point in the history
  • Loading branch information
romainruaud committed Jan 22, 2025
1 parent 2827e8f commit 9fc064c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
5 changes: 2 additions & 3 deletions .upsun/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ applications:
variables:
env:
NEXT_PUBLIC_API_ROUTE_PREFIX: 'api'
NEXT_PUBLIC_API_URL: 'https://upsun-deployment-config-3xlvpkq-kxux3rltbhsgo.fr-3.platformsh.site/api'
mounts:
"/.npm":
source: "storage"
Expand All @@ -24,8 +23,8 @@ applications:
printenv
yarn
yarn install --frozen-lockfile --network-timeout 120000
ls -ail node_modules
ls -ail pwa/node_modules
patch -p1 < next-api-route.patch
cat node_modules/@elastic-suite/gally-admin-shared/src/constants/api.ts
yarn build
deploy: |
set -eux
Expand Down
32 changes: 32 additions & 0 deletions front/next-api-route.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
From 5b5d1f65e427540a819debcabd8f038be74f1f3e Mon Sep 17 00:00:00 2001
From: Botis <[email protected]>
Date: Fri, 10 Jan 2025 17:15:03 +0100
Subject: [PATCH] fix: api url not correctly built, empty NEXT_PUBLIC_API_URL
or REACT_APP_API_URL was taken in account

---
node_modules/@elastic-suite/gally-admin-shared/src/constants/api.ts | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/node_modules/@elastic-suite/gally-admin-shared/src/constants/api.ts b/node_modules/@elastic-suite/gally-admin-shared/src/constants/api.ts
index a1ac2a1e..425a7bb2 100644
--- a/node_modules/@elastic-suite/gally-admin-shared/src/constants/api.ts
+++ b/node_modules/@elastic-suite/gally-admin-shared/src/constants/api.ts
@@ -1,9 +1,14 @@
let url =
process.env.NODE_ENV === 'test'
? 'http://localhost/'
- : process.env.NEXT_PUBLIC_API_URL ??
- process.env.REACT_APP_API_URL ??
- (typeof window !== 'undefined' ? window.location.origin : '')
+ : process.env.NEXT_PUBLIC_API_URL
+ ? process.env.NEXT_PUBLIC_API_URL
+ : process.env.REACT_APP_API_URL
+ ? process.env.REACT_APP_API_URL
+ : `${typeof window !== 'undefined' ? window.location.origin : ''}/${
+ process.env.NEXT_PUBLIC_API_ROUTE_PREFIX
+ }`
+
if (url && String(url).endsWith('/')) {
url = url.slice(0, -1)
}

0 comments on commit 9fc064c

Please sign in to comment.