File size: 1,173 Bytes
8aedc84
b91acfc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// place files you want to import through the `$lib` alias in this folder.

/**
 * Get the server URL based on environment variables and dev/prod mode
 * Priority: ENV variable > dev mode (localhost:8000) > prod mode (HF Space)
 */
export function getServerUrl(): string {
  // Check for environment variable first
  if (typeof window !== 'undefined') {
    // Client-side: check for runtime environment variable
    const envUrl = (window as any).__SERVER_URL__;
    if (envUrl) {
      return envUrl;
    }
  } else {
    // Server-side: check for build-time environment variable
    const envUrl = process.env.PUBLIC_SERVER_URL;
    if (envUrl) {
      return envUrl;
    }
  }

  // Fall back to dev/prod detection
  if (typeof window !== 'undefined') {
    // Client-side: check if we're in development
    const isDev = window.location.hostname === 'localhost' || 
                  window.location.hostname === '127.0.0.1' ||
                  window.location.hostname.startsWith('192.168.');
    
    return isDev ? 'http://localhost:8000' : 'https://blanchon-robottransportserver.hf.space/api';
  }
  
  // Server-side fallback
  return 'http://localhost:8000';
}