mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 02:50:00 +08:00
Ship the breaking front- and back-end runtime and route refactor, learner and guardian flows, grounded reading, knowledge and parser updates, and recoverable long-running streams. Release notes: assets/releases/ver1-6-3.md
27 lines
1008 B
TypeScript
27 lines
1008 B
TypeScript
type BackendRuntimeEnvironment = Record<string, string | undefined>;
|
|
|
|
const DEFAULT_BACKEND_API_BASE = "http://127.0.0.1:8001";
|
|
|
|
function nonEmpty(value: string | undefined): string | undefined {
|
|
const normalized = value?.trim();
|
|
return normalized ? normalized : undefined;
|
|
}
|
|
|
|
/** Resolve the address used by the Next server to reach FastAPI. */
|
|
export function resolveBackendApiBase(
|
|
env: BackendRuntimeEnvironment = process.env,
|
|
): string {
|
|
const privateBase = nonEmpty(env.DEEPTUTOR_API_BASE_URL);
|
|
if (privateBase) return privateBase;
|
|
|
|
// `next dev` can isolate Proxy in a worker that keeps conventional and
|
|
// Next-managed variables but drops arbitrary process variables. Rebuild the
|
|
// launcher's loopback origin from the port before using its public fallback.
|
|
const backendPort = nonEmpty(env.BACKEND_PORT);
|
|
if (backendPort && /^\d+$/.test(backendPort)) {
|
|
return `http://127.0.0.1:${backendPort}`;
|
|
}
|
|
|
|
return nonEmpty(env.NEXT_PUBLIC_API_BASE) ?? DEFAULT_BACKEND_API_BASE;
|
|
}
|