feat: add dynamic base URL configuration using environment variables (#1511)

- Replace hardcoded base URL in HttpClient.ts with environment variable support
- Add NEXT_PUBLIC_API_BASE_URL environment variable for dynamic configuration
- Add dev:local script for development with localhost:5300 backend
- Development: uses localhost:5300, Production: uses / (relative path)
- Eliminates need for manual code changes when switching environments

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Junyan Qin <Chin>, 秦骏言 in Chinese, you can call me my english name Rock Chin. <rockchinq@gmail.com>
This commit is contained in:
devin-ai-integration[bot]
2025-06-08 17:44:40 +08:00
committed by GitHub
parent 793f0a9c10
commit f271608114
2 changed files with 10 additions and 3 deletions

View File

@@ -4,6 +4,7 @@
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"dev:local": "NEXT_PUBLIC_API_BASE_URL=http://localhost:5300 next dev --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint",

View File

@@ -494,9 +494,15 @@ class HttpClient {
}
}
// export const httpClient = new HttpClient('https://event-log.langbot.dev');
// export const httpClient = new HttpClient('http://localhost:5300');
export const httpClient = new HttpClient('/');
const getBaseURL = (): string => {
if (typeof window !== 'undefined' && process.env.NEXT_PUBLIC_API_BASE_URL) {
return process.env.NEXT_PUBLIC_API_BASE_URL;
}
return '/';
};
export const httpClient = new HttpClient(getBaseURL());
// 临时写法未来两种Client都继承自HttpClient父类不允许共享方法
export const spaceClient = new HttpClient('https://space.langbot.app');