refactor(desktop): SaaS URL 集中配置化,消除 5 处硬编码
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
- 新增 .env.development / .env.production (VITE_SAAS_URL) - saasStore.ts / LoginPage.tsx / saas-client.ts / SaaSLogin.tsx 统一读取 import.meta.env.VITE_SAAS_URL - 移除 LoginPage 中未使用的 isTauriRuntime import
This commit is contained in:
5
desktop/.env.development
Normal file
5
desktop/.env.development
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# SaaS 服务地址(开发环境)
|
||||||
|
VITE_SAAS_URL=http://127.0.0.1:8080
|
||||||
|
# Gateway 服务地址(开发环境)
|
||||||
|
VITE_GATEWAY_HTTP=http://127.0.0.1:50051
|
||||||
|
VITE_GATEWAY_WS=ws://127.0.0.1:50051/ws
|
||||||
5
desktop/.env.production
Normal file
5
desktop/.env.production
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# SaaS 服务地址(生产环境)
|
||||||
|
VITE_SAAS_URL=https://saas.zclaw.com
|
||||||
|
# Gateway 服务地址(生产环境)
|
||||||
|
VITE_GATEWAY_HTTP=https://gateway.zclaw.com
|
||||||
|
VITE_GATEWAY_WS=wss://gateway.zclaw.com/ws
|
||||||
@@ -22,12 +22,10 @@ import {
|
|||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { useSaaSStore } from '../store/saasStore';
|
import { useSaaSStore } from '../store/saasStore';
|
||||||
import { cn } from '../lib/utils';
|
import { cn } from '../lib/utils';
|
||||||
import { isTauriRuntime } from '../lib/tauri-gateway';
|
|
||||||
|
|
||||||
// === Constants ===
|
// === Constants ===
|
||||||
|
|
||||||
const PRODUCTION_SAAS_URL = 'https://saas.zclaw.com';
|
const SAAS_URL = import.meta.env.VITE_SAAS_URL || 'http://127.0.0.1:8080';
|
||||||
const DEV_SAAS_URL = 'http://127.0.0.1:8080';
|
|
||||||
|
|
||||||
// === Animation Variants ===
|
// === Animation Variants ===
|
||||||
|
|
||||||
@@ -86,8 +84,7 @@ function ZclawLogo({ className }: { className?: string }) {
|
|||||||
|
|
||||||
/** 根据运行环境自动选择 SaaS 服务器地址 */
|
/** 根据运行环境自动选择 SaaS 服务器地址 */
|
||||||
function getSaasUrl(): string {
|
function getSaasUrl(): string {
|
||||||
if (import.meta.env.DEV) return DEV_SAAS_URL;
|
return SAAS_URL;
|
||||||
return isTauriRuntime() ? PRODUCTION_SAAS_URL : DEV_SAAS_URL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// === Component ===
|
// === Component ===
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ export function SaaSLogin({ onLogin, onLoginWithTotp, onRegister, initialUrl, is
|
|||||||
type="url"
|
type="url"
|
||||||
value={serverUrl}
|
value={serverUrl}
|
||||||
onChange={(e) => setServerUrl(e.target.value)}
|
onChange={(e) => setServerUrl(e.target.value)}
|
||||||
placeholder="https://saas.zclaw.com"
|
placeholder={import.meta.env.VITE_SAAS_URL || 'http://127.0.0.1:8080'}
|
||||||
className="w-full pl-10 pr-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 bg-white text-gray-900"
|
className="w-full pl-10 pr-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 bg-white text-gray-900"
|
||||||
disabled={isLoggingIn}
|
disabled={isLoggingIn}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -508,4 +508,4 @@ export interface SaaSClient {
|
|||||||
* Global SaaS client singleton.
|
* Global SaaS client singleton.
|
||||||
* Initialized with a default URL; the URL and token are updated on login.
|
* Initialized with a default URL; the URL and token are updated on login.
|
||||||
*/
|
*/
|
||||||
export const saasClient = new SaaSClient('https://saas.zclaw.com');
|
export const saasClient = new SaaSClient(import.meta.env.VITE_SAAS_URL || 'http://127.0.0.1:8080');
|
||||||
|
|||||||
@@ -128,9 +128,7 @@ export type SaaSStore = SaaSStateSlice & SaaSActionsSlice;
|
|||||||
|
|
||||||
// === Constants ===
|
// === Constants ===
|
||||||
|
|
||||||
const DEFAULT_SAAS_URL = import.meta.env.DEV
|
const DEFAULT_SAAS_URL = import.meta.env.VITE_SAAS_URL || 'http://127.0.0.1:8080';
|
||||||
? 'http://127.0.0.1:8080'
|
|
||||||
: 'https://saas.zclaw.com';
|
|
||||||
|
|
||||||
// === Helpers ===
|
// === Helpers ===
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user