|
1 | | -const isTesting = false; |
| 1 | +// Check if we're in a browser environment |
| 2 | +const isBrowser = typeof window !== 'undefined'; |
2 | 3 |
|
3 | | -export const url = isTesting |
4 | | - ? { |
5 | | - backendURL: '', |
6 | | - frontendURL: '', |
7 | | - containerOrigin: '', |
8 | | - githubRepoURL: '', |
9 | | - githubDocsURL: '', |
10 | | - zulipURL: '', |
11 | | - taskwarriorURL: '', |
12 | | - taskchampionSyncServerURL: '', |
13 | | - } |
14 | | - : { |
15 | | - backendURL: import.meta.env.VITE_BACKEND_URL || 'http://localhost:8000/', |
16 | | - frontendURL: import.meta.env.VITE_FRONTEND_URL || 'http://localhost:80', |
17 | | - containerOrigin: |
18 | | - import.meta.env.VITE_CONTAINER_ORIGIN || 'http://localhost:8080/', |
19 | | - githubRepoURL: 'https://github.com/CCExtractor/ccsync', |
20 | | - githubDocsURL: 'https://its-me-abhishek.github.io/ccsync-docs/', |
21 | | - zulipURL: 'https://ccextractor.org/public/general/support/', |
22 | | - taskwarriorURL: 'https://taskwarrior.org/docs/', |
23 | | - taskchampionSyncServerURL: |
24 | | - 'https://github.com/GothenburgBitFactory/taskchampion-sync-server/tree/main', |
25 | | - }; |
| 4 | +// Helper to get the WebSocket URL for the current host |
| 5 | +export const getWebSocketURL = (path: string): string => { |
| 6 | + if (!isBrowser) { |
| 7 | + return `ws://localhost:8000/${path}`; |
| 8 | + } |
| 9 | + const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; |
| 10 | + return `${protocol}//${window.location.host}/${path}`; |
| 11 | +}; |
| 12 | + |
| 13 | +// Helper to get the sync server URL (shown to users in SetupGuide) |
| 14 | +const getSyncServerURL = (): string => { |
| 15 | + if (!isBrowser) { |
| 16 | + return 'http://localhost:8080/'; |
| 17 | + } |
| 18 | + return `${window.location.origin}/taskchampion/`; |
| 19 | +}; |
| 20 | + |
| 21 | +export const url = { |
| 22 | + // Backend API calls use relative URLs - nginx routes to backend |
| 23 | + backendURL: '/', |
| 24 | + |
| 25 | + // Frontend URL for redirects - just use root |
| 26 | + frontendURL: '/', |
| 27 | + |
| 28 | + // Sync server URL - derived from current origin |
| 29 | + // This is shown to users in SetupGuide for their taskwarrior config |
| 30 | + containerOrigin: getSyncServerURL(), |
| 31 | + |
| 32 | + // External URLs (unchanged) |
| 33 | + githubRepoURL: 'https://github.com/CCExtractor/ccsync', |
| 34 | + githubDocsURL: 'https://its-me-abhishek.github.io/ccsync-docs/', |
| 35 | + zulipURL: 'https://ccextractor.org/public/general/support/', |
| 36 | + taskwarriorURL: 'https://taskwarrior.org/docs/', |
| 37 | + taskchampionSyncServerURL: |
| 38 | + 'https://github.com/GothenburgBitFactory/taskchampion-sync-server/tree/main', |
| 39 | +}; |
0 commit comments