File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 33}
44
55:8080 {
6- handle /api/* {
6+ # Handle API requests under the base path
7+ handle_path {$OXO_PUBLIC_URL} api/* {
78 reverse_proxy {$OXO_BACKEND_URL}
8- }
9+ }
10+ # Handle all other requests under the base path (frontend SPA)
911 handle_path {$OXO_PUBLIC_URL} * {
1012 root * /opt/oxo2-frontend/dist
1113 try_files {path} {path} / /index.html
Original file line number Diff line number Diff line change @@ -2,9 +2,25 @@ export async function doHTTPRequest<T>(
22 path : string ,
33 request ?: RequestInit | undefined
44) : Promise < T > {
5- const BASE_URL = import . meta. env . OXO_BACKEND_URL || 'http://localhost:8081' ;
5+ // In production (when OXO_PUBLIC_URL is set), always use relative URLs through Caddy proxy
6+ // In local development (no OXO_PUBLIC_URL), use OXO_BACKEND_URL directly
7+ const backendUrl = import . meta. env . OXO_BACKEND_URL ;
8+ const publicUrl = import . meta. env . OXO_PUBLIC_URL || '' ;
9+
10+ let requestUrl : string ;
11+ if ( publicUrl && publicUrl !== '/' ) {
12+ // Production: use relative URL through Caddy proxy, prefixed with base path
13+ requestUrl = `${ publicUrl } ${ path } ` ;
14+ } else if ( backendUrl ) {
15+ // Local development: use absolute URL directly to backend
16+ requestUrl = `${ backendUrl } ${ path } ` ;
17+ } else {
18+ // Fallback: use relative URL (shouldn't happen in normal operation)
19+ requestUrl = path ;
20+ }
21+
622 const response : Response = await fetch (
7- ` ${ BASE_URL } ${ path } ` ,
23+ requestUrl ,
824 {
925 ...( request ? request : { } ) ,
1026 }
You can’t perform that action at this time.
0 commit comments