From 2d7decc96476ff14ec8274c1c9387513e1864022 Mon Sep 17 00:00:00 2001
From: Niclas Blomberg <nicke.blomberg@gmail.com>
Date: Fri, 29 Sep 2023 16:44:09 +0300
Subject: [PATCH] fix(relay-dashboard): use domain for client side requests

---
 src/relay/components/CheckRegistrationWidget.tsx | 2 +-
 src/relay/config.ts                              | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/relay/components/CheckRegistrationWidget.tsx b/src/relay/components/CheckRegistrationWidget.tsx
index e7b8366e..7f6a9b86 100644
--- a/src/relay/components/CheckRegistrationWidget.tsx
+++ b/src/relay/components/CheckRegistrationWidget.tsx
@@ -13,7 +13,7 @@ const CheckRegistrationWidget: FC = () => {
   const [registrationStatus, setRegistrationStatus] =
     useState<Status>("initial");
 
-  const apiUrl = getDomain();
+  const apiUrl = getDomain(true);
 
   const fetchRegistrationStatus = () => {
     if (addr.length > 0) {
diff --git a/src/relay/config.ts b/src/relay/config.ts
index affc1ce7..d986722a 100644
--- a/src/relay/config.ts
+++ b/src/relay/config.ts
@@ -3,7 +3,7 @@ import * as SharedConfig from "../config";
 // Inside the cluster, we need to use the k8s service name to call the api.
 // Outside the cluster, e.g. during build, we need to use the domain name.
 
-export const getDomain = () => {
+export const getDomain = (isClientSide: boolean = false) => {
   const apiEnv = SharedConfig.apiEnvFromEnv();
   const isBuild = process.env.BUILD === "true";
 
@@ -11,11 +11,13 @@ export const getDomain = () => {
     case "dev":
       return "http://relay.localhost:3000";
     case "stag":
-      return isBuild
+      return isBuild || isClientSide
         ? "https://relay-stag.ultrasound.money"
         : "http://website-api";
     case "prod":
-      return isBuild ? "https://relay.ultrasound.money" : "http://website-api";
+      return isBuild || isClientSide
+        ? "https://relay.ultrasound.money"
+        : "http://website-api";
   }
 };