rebuild app as turbopack-first single-stack with internal api and openclaw tasks
This commit is contained in:
@@ -2,44 +2,12 @@ function trimTrailingSlash(value: string) {
|
||||
return value.endsWith('/') ? value.slice(0, -1) : value;
|
||||
}
|
||||
|
||||
function isInternalHost(hostname: string) {
|
||||
return hostname === 'backend'
|
||||
|| hostname === 'localhost'
|
||||
|| hostname === '127.0.0.1'
|
||||
|| hostname.endsWith('.internal');
|
||||
}
|
||||
|
||||
function parseUrl(url: string) {
|
||||
try {
|
||||
return new URL(url);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveApiBaseURL(configuredBaseURL: string | undefined) {
|
||||
const fallbackLocal = 'http://localhost:3001';
|
||||
const candidate = configuredBaseURL?.trim() || fallbackLocal;
|
||||
const candidate = configuredBaseURL?.trim();
|
||||
|
||||
if (typeof window === 'undefined') {
|
||||
return trimTrailingSlash(candidate);
|
||||
if (!candidate) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const parsed = parseUrl(candidate);
|
||||
|
||||
if (!parsed) {
|
||||
return `${window.location.origin}`;
|
||||
}
|
||||
|
||||
const browserHost = window.location.hostname;
|
||||
const browserIsLocal = browserHost === 'localhost' || browserHost === '127.0.0.1';
|
||||
|
||||
if (!browserIsLocal && isInternalHost(parsed.hostname)) {
|
||||
console.warn(
|
||||
`[fiscal] NEXT_PUBLIC_API_URL is internal (${parsed.hostname}); falling back to https://api.${browserHost}`
|
||||
);
|
||||
return trimTrailingSlash(`https://api.${browserHost}`);
|
||||
}
|
||||
|
||||
return trimTrailingSlash(parsed.toString());
|
||||
return trimTrailingSlash(candidate);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user