Skip to content

Commit 1c4e9fc

Browse files
committed
Apply patch to react app to manage api prefix dynamically.
1 parent 2827e8f commit 1c4e9fc

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

.upsun/config.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ applications:
66
variables:
77
env:
88
NEXT_PUBLIC_API_ROUTE_PREFIX: 'api'
9-
NEXT_PUBLIC_API_URL: 'https://upsun-deployment-config-3xlvpkq-kxux3rltbhsgo.fr-3.platformsh.site/api'
109
mounts:
1110
"/.npm":
1211
source: "storage"
@@ -24,8 +23,7 @@ applications:
2423
printenv
2524
yarn
2625
yarn install --frozen-lockfile --network-timeout 120000
27-
ls -ail node_modules
28-
ls -ail pwa/node_modules
26+
patch -p1 < next-api-route.patch
2927
yarn build
3028
deploy: |
3129
set -eux

front/next-api-route.patch

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
From 5b5d1f65e427540a819debcabd8f038be74f1f3e Mon Sep 17 00:00:00 2001
2+
From: Botis <botis@smile.fr>
3+
Date: Fri, 10 Jan 2025 17:15:03 +0100
4+
Subject: [PATCH] fix: api url not correctly built, empty NEXT_PUBLIC_API_URL
5+
or REACT_APP_API_URL was taken in account
6+
7+
---
8+
node_modules/@elastic-suite/gally-admin-shared/src/constants/api.ts | 11 ++++++++---
9+
1 file changed, 8 insertions(+), 3 deletions(-)
10+
11+
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
12+
index a1ac2a1e..425a7bb2 100644
13+
--- a/node_modules/@elastic-suite/gally-admin-shared/src/constants/api.ts
14+
+++ b/node_modules/@elastic-suite/gally-admin-shared/src/constants/api.ts
15+
@@ -1,9 +1,14 @@
16+
let url =
17+
process.env.NODE_ENV === 'test'
18+
? 'http://localhost/'
19+
- : process.env.NEXT_PUBLIC_API_URL ??
20+
- process.env.REACT_APP_API_URL ??
21+
- (typeof window !== 'undefined' ? window.location.origin : '')
22+
+ : process.env.NEXT_PUBLIC_API_URL
23+
+ ? process.env.NEXT_PUBLIC_API_URL
24+
+ : process.env.REACT_APP_API_URL
25+
+ ? process.env.REACT_APP_API_URL
26+
+ : `${typeof window !== 'undefined' ? window.location.origin : ''}/${
27+
+ process.env.NEXT_PUBLIC_API_ROUTE_PREFIX
28+
+ }`
29+
+
30+
if (url && String(url).endsWith('/')) {
31+
url = url.slice(0, -1)
32+
}

0 commit comments

Comments
 (0)