feat(dev-server): 添加开发模式 HTTP/WebSocket 服务器
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

功能:
- 创建 dev_server.rs 模块,提供 HTTP/WebSocket API
- 使用 feature flag \dev-server\ 控制编译
- 仅绑定 localhost:50051,安全限制 CORS
- 生产构建不包含此模块

使用方式:
- pnpm tauri:dev:web - 启动带开发服务器的 Tauri
- pnpm tauri:dev - 常规开发模式(无服务器)

安全:
- 仅 localhost 绑定
- CORS 限制为 Vite 开发端口
- 通过 feature flag 完全移除生产代码
This commit is contained in:
iven
2026-03-26 17:38:53 +08:00
parent b7f3d94950
commit 85bf47bebb
8 changed files with 615 additions and 263 deletions

View File

@@ -29,6 +29,10 @@ mod kernel_commands;
// Pipeline commands (DSL-based workflows)
mod pipeline_commands;
// Development server (optional, for web debugging)
#[cfg(feature = "dev-server")]
mod dev_server;
use serde::Serialize;
use serde_json::{json, Value};
use std::fs;
@@ -1303,6 +1307,25 @@ fn gateway_doctor(app: AppHandle) -> Result<String, String> {
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
// Start development server when dev-server feature is enabled
#[cfg(feature = "dev-server")]
{
std::thread::spawn(|| {
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime for dev server");
rt.block_on(async {
match dev_server::start_dev_server().await {
Ok((_state, _handle)) => {
tracing::info!("[DevServer] Development server started on port {}", dev_server::DEV_SERVER_PORT);
}
Err(e) => {
tracing::error!("[DevServer] Failed to start: {}", e);
}
}
std::future::pending::<()>().await;
});
});
}
// Initialize Viking storage (async, in background)
let runtime = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime");
runtime.block_on(async {