mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
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:
committed by
GitHub
parent
793f0a9c10
commit
f271608114
@@ -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",
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user