@@ -19,7 +19,7 @@ import { Skeleton } from "@/components/ui/skeleton";
1919import type { SearchSpace } from "@/contracts/types/search-space.types" ;
2020import { searchSpacesApiService } from "@/lib/apis/search-spaces-api.service" ;
2121import { authenticatedFetch } from "@/lib/auth-utils" ;
22- import { BACKEND_URL } from "@/lib/env-config" ;
22+ import { buildBackendUrl } from "@/lib/env-config" ;
2323import { cn } from "@/lib/utils" ;
2424
2525type GatewayConnection = {
@@ -82,13 +82,14 @@ export function MessagingChannelsContent() {
8282 const discordGatewayEnabled = gatewayConfig ?. discord_enabled ?? false ;
8383
8484 const fetchConnections = useCallback ( async ( platform ?: GatewayPlatform ) => {
85- const query = platform ? `?platform=${ encodeURIComponent ( platform ) } ` : "" ;
86- const res = await authenticatedFetch ( `${ BACKEND_URL } /api/v1/gateway/connections${ query } ` ) ;
85+ const res = await authenticatedFetch (
86+ buildBackendUrl ( "/api/v1/gateway/connections" , platform ? { platform } : undefined )
87+ ) ;
8788 return ( await res . json ( ) ) as GatewayConnection [ ] ;
8889 } , [ ] ) ;
8990
9091 const fetchGatewayConfig = useCallback ( async ( ) => {
91- const res = await authenticatedFetch ( ` ${ BACKEND_URL } /api/v1/gateway/config` ) ;
92+ const res = await authenticatedFetch ( buildBackendUrl ( " /api/v1/gateway/config" ) ) ;
9293 return ( await res . json ( ) ) as GatewayConfig ;
9394 } , [ ] ) ;
9495
@@ -125,7 +126,9 @@ export function MessagingChannelsContent() {
125126
126127 const refreshBaileysHealth = useCallback ( async ( ) => {
127128 if ( whatsappMode !== "baileys" ) return ;
128- const res = await authenticatedFetch ( `${ BACKEND_URL } /api/v1/gateway/whatsapp/baileys/health` ) ;
129+ const res = await authenticatedFetch (
130+ buildBackendUrl ( "/api/v1/gateway/whatsapp/baileys/health" )
131+ ) ;
129132 if ( ! res . ok ) return ;
130133 const data = ( await res . json ( ) ) as BaileysHealth ;
131134 setBaileysHealth ( data ) ;
@@ -136,7 +139,7 @@ export function MessagingChannelsContent() {
136139 } , [ refreshBaileysHealth ] ) ;
137140
138141 async function startPairing ( platform : PairingPlatform ) {
139- const res = await authenticatedFetch ( ` ${ BACKEND_URL } /api/v1/gateway/bindings/start` , {
142+ const res = await authenticatedFetch ( buildBackendUrl ( " /api/v1/gateway/bindings/start" ) , {
140143 method : "POST" ,
141144 headers : { "Content-Type" : "application/json" } ,
142145 body : JSON . stringify ( { platform, search_space_id : searchSpaceId } ) ,
@@ -148,7 +151,7 @@ export function MessagingChannelsContent() {
148151
149152 async function installSlackGateway ( ) {
150153 const res = await authenticatedFetch (
151- ` ${ BACKEND_URL } /api/v1/gateway/slack/install?search_space_id= ${ searchSpaceId } `
154+ buildBackendUrl ( " /api/v1/gateway/slack/install" , { search_space_id : searchSpaceId } )
152155 ) ;
153156 if ( ! res . ok ) return ;
154157 const data = ( await res . json ( ) ) as { auth_url ?: string } ;
@@ -159,7 +162,7 @@ export function MessagingChannelsContent() {
159162
160163 async function installDiscordGateway ( ) {
161164 const res = await authenticatedFetch (
162- ` ${ BACKEND_URL } /api/v1/gateway/discord/install?search_space_id= ${ searchSpaceId } `
165+ buildBackendUrl ( " /api/v1/gateway/discord/install" , { search_space_id : searchSpaceId } )
163166 ) ;
164167 if ( ! res . ok ) return ;
165168 const data = ( await res . json ( ) ) as { auth_url ?: string } ;
@@ -181,8 +184,8 @@ export function MessagingChannelsContent() {
181184 async function revoke ( connection : GatewayConnection ) {
182185 const url =
183186 connection . route_type === "account" && connection . account_id
184- ? ` ${ BACKEND_URL } /api/v1/gateway/accounts/${ connection . account_id } `
185- : ` ${ BACKEND_URL } /api/v1/gateway/bindings/${ connection . id } `;
187+ ? buildBackendUrl ( ` /api/v1/gateway/accounts/${ connection . account_id } `)
188+ : buildBackendUrl ( ` /api/v1/gateway/bindings/${ connection . id } `) ;
186189 await authenticatedFetch ( url , {
187190 method : "DELETE" ,
188191 } ) ;
@@ -205,8 +208,8 @@ export function MessagingChannelsContent() {
205208 ) ;
206209 const url =
207210 connection . route_type === "account" && connection . account_id
208- ? ` ${ BACKEND_URL } /api/v1/gateway/accounts/${ connection . account_id } /search-space`
209- : ` ${ BACKEND_URL } /api/v1/gateway/bindings/${ connection . id } /search-space`;
211+ ? buildBackendUrl ( ` /api/v1/gateway/accounts/${ connection . account_id } /search-space`)
212+ : buildBackendUrl ( ` /api/v1/gateway/bindings/${ connection . id } /search-space`) ;
210213 const res = await authenticatedFetch ( url , {
211214 method : "PATCH" ,
212215 headers : { "Content-Type" : "application/json" } ,
@@ -222,9 +225,12 @@ export function MessagingChannelsContent() {
222225 }
223226
224227 async function resume ( connection : GatewayConnection ) {
225- await authenticatedFetch ( `${ BACKEND_URL } /api/v1/gateway/bindings/${ connection . id } /resume` , {
226- method : "POST" ,
227- } ) ;
228+ await authenticatedFetch (
229+ buildBackendUrl ( `/api/v1/gateway/bindings/${ connection . id } /resume` ) ,
230+ {
231+ method : "POST" ,
232+ }
233+ ) ;
228234 await refreshPlatform ( connection . platform as GatewayPlatform ) ;
229235 }
230236
0 commit comments