Client-Tauri客户端支持灵活的API地址配置,可以根据不同环境(开发/测试/生产)自动切换后端服务地址。
客户端首次运行时会自动创建默认配置文件:
{
"api": {
"base_url": "http://localhost:8000",
"timeout": 30,
"software_code": "buff-xp-steam-sh"
},
"security": {
"encryption_enabled": true,
"key_rotation_days": 10,
"heartbeat_interval": 30
}
}
%APPDATA%\BuffClient\config.json~/Library/Application Support/BuffClient/config.json~/.local/share/BuffClient/config.json| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
base_url |
string | "http://localhost:8000" |
后端API服务器地址 |
timeout |
number | 30 |
请求超时时间(秒) |
software_code |
string | "buff-xp-steam-sh" |
软件标识码(与后端约定) |
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
encryption_enabled |
boolean | true |
是否启用数据加密 |
key_rotation_days |
number | 10 |
密钥轮换周期(天) |
heartbeat_interval |
number | 30 |
心跳检测间隔(秒) |
# 首次运行客户端,会自动创建默认配置
npm run tauri:dev
# 或
npm run tauri:build
# Windows
mkdir "%APPDATA%\BuffClient"
copy "default-config.json" "%APPDATA%\BuffClient\config.json"
# macOS
mkdir -p "~/Library/Application Support/BuffClient"
cp "default-config.json" "~/Library/Application Support/BuffClient/config.json"
# Linux
mkdir -p "~/.local/share/BuffClient"
cp "default-config.json" "~/.local/share/BuffClient/config.json"
// 在前端界面中调用
await window.__TAURI__.invoke('update_api_url', {
newUrl: 'https://your-production-api.com'
});
{
"api": {
"base_url": "http://localhost:8000",
"timeout": 30,
"software_code": "buff-xp-steam-sh"
}
}
{
"api": {
"base_url": "http://test-api.example.com",
"timeout": 60,
"software_code": "buff-xp-steam-sh"
}
}
{
"api": {
"base_url": "https://api.buff-client.com",
"timeout": 30,
"software_code": "buff-xp-steam-sh"
}
}
# 查看当前配置
cat "$(配置文件路径)/config.json"
# 启动客户端,查看日志输出
npm run tauri:dev
// 获取当前API配置
const config = await window.__TAURI__.invoke('get_app_config');
console.log('当前API地址:', config.api.base_url);
# 手动创建配置目录并复制默认配置
mkdir -p "$(配置目录)"
cp "default-config.json" "$(配置目录)/config.json"
# 验证JSON格式
cat config.json | python -m json.tool
base_url 是否正确如果配置过程中遇到问题,请: