feat: 收口 Rust Web 3000 主链
This commit is contained in:
@@ -7,8 +7,8 @@ mod gateway;
|
||||
mod health;
|
||||
mod hermes;
|
||||
mod kernel;
|
||||
mod local_folder_source;
|
||||
mod local_folder_events;
|
||||
mod local_folder_source;
|
||||
mod local_markdown_parser;
|
||||
mod media;
|
||||
mod mindmap_api;
|
||||
@@ -30,7 +30,6 @@ use axum::Router;
|
||||
|
||||
pub fn build_router(state: AppState) -> Router {
|
||||
let hermes_base_path = state.config().hermes_base_path.clone();
|
||||
let compat_next_base_path = state.config().compat_next_base_path.clone();
|
||||
let enable_debug_shell_routes = state.config().enable_debug_shell_routes;
|
||||
|
||||
let mut router = Router::new()
|
||||
@@ -91,7 +90,6 @@ pub fn build_router(state: AppState) -> Router {
|
||||
)
|
||||
.route("/api/documents/meta", get(documents::meta))
|
||||
.route("/api/documents/content", get(documents::content))
|
||||
.route("/api/documents/page", get(web_shell::documents_page_compat))
|
||||
.route("/api/documents/purge", post(documents::purge))
|
||||
.route("/api/documents/title", post(documents::title))
|
||||
.route("/api/documents/options", post(documents::options))
|
||||
@@ -137,21 +135,132 @@ pub fn build_router(state: AppState) -> Router {
|
||||
Router::new()
|
||||
.route("/health", get(hermes::health))
|
||||
.route("/bridge", post(hermes::bridge_runtime)),
|
||||
)
|
||||
.nest(
|
||||
&compat_next_base_path,
|
||||
Router::new()
|
||||
.route("/ai-agent/run", post(compat::next_ai_agent_run))
|
||||
.route("/sidebar", get(compat::next_sidebar)),
|
||||
)
|
||||
.fallback(gateway::legacy_next_proxy);
|
||||
);
|
||||
|
||||
if enable_debug_shell_routes {
|
||||
router = router
|
||||
.route("/tree", get(tree::tree_shell))
|
||||
.route("/document-debug", get(editor::document_editor_shell))
|
||||
.route("/document", get(editor::document_editor_shell));
|
||||
.route("/document-debug", get(editor::document_editor_shell));
|
||||
}
|
||||
|
||||
router.with_state(state)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::build_router;
|
||||
use crate::app::{AppConfig, AppState};
|
||||
use axum::body::Body;
|
||||
use axum::http::{Request, StatusCode};
|
||||
use axum::Router;
|
||||
use tower::ServiceExt;
|
||||
|
||||
fn app(enable_debug_shell_routes: bool) -> Router {
|
||||
build_router(AppState::new(AppConfig {
|
||||
service_name: "mnote-web".into(),
|
||||
service_version: "0.1.0".into(),
|
||||
bind_addr: "127.0.0.1:0".into(),
|
||||
public_bind_addr: "127.0.0.1:3000".into(),
|
||||
legacy_next_base_url: Some("http://127.0.0.1:3100".into()),
|
||||
enable_legacy_next_compat: false,
|
||||
enable_debug_shell_routes,
|
||||
hermes_base_path: "/api/hermes".into(),
|
||||
compat_next_base_path: "/api/compat/next".into(),
|
||||
convex_url: None,
|
||||
convex_admin_key: None,
|
||||
allow_dev_fixtures: false,
|
||||
query_fixtures_json: None,
|
||||
mutation_fixtures_json: None,
|
||||
dev_user_id: "dev-user".into(),
|
||||
dev_user_name: "开发用户".into(),
|
||||
dev_user_email: "dev@mnote.local".into(),
|
||||
}))
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn debug_shell_routes_are_not_mounted_by_default() {
|
||||
for path in ["/tree", "/document-debug"] {
|
||||
let response = app(false)
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.uri(path)
|
||||
.body(Body::empty())
|
||||
.expect("request"),
|
||||
)
|
||||
.await
|
||||
.expect("response");
|
||||
assert_eq!(
|
||||
response.status(),
|
||||
StatusCode::NOT_FOUND,
|
||||
"{path} 默认不应暴露"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn debug_shell_routes_are_only_available_when_explicitly_enabled() {
|
||||
let tree_response = app(true)
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.uri("/tree")
|
||||
.body(Body::empty())
|
||||
.expect("request"),
|
||||
)
|
||||
.await
|
||||
.expect("response");
|
||||
assert_ne!(
|
||||
tree_response.status(),
|
||||
StatusCode::NOT_FOUND,
|
||||
"/tree 显式启用 debug gate 后不应继续返回 404",
|
||||
);
|
||||
|
||||
let document_debug_response = app(true)
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.uri("/document-debug")
|
||||
.body(Body::empty())
|
||||
.expect("request"),
|
||||
)
|
||||
.await
|
||||
.expect("response");
|
||||
assert_ne!(
|
||||
document_debug_response.status(),
|
||||
StatusCode::NOT_FOUND,
|
||||
"/document-debug 显式启用 debug gate 后不应继续返回 404",
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn onlyoffice_and_media_transport_routes_are_explicitly_mounted() {
|
||||
for (method, path) in [
|
||||
("GET", "/onlyoffice"),
|
||||
("POST", "/api/onlyoffice/sign"),
|
||||
("GET", "/api/onlyoffice/proxy?u=x"),
|
||||
("POST", "/api/onlyoffice/callback"),
|
||||
("POST", "/api/onlyoffice/forcesave"),
|
||||
("POST", "/api/media/upload"),
|
||||
("GET", "/api/media/sign?assetId=x"),
|
||||
("POST", "/api/tree/filetree/upload-target-preflight"),
|
||||
(
|
||||
"GET",
|
||||
"/onlyoffice-server/web-apps/apps/api/documents/api.js",
|
||||
),
|
||||
] {
|
||||
let response = app(false)
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method(method)
|
||||
.uri(path)
|
||||
.body(Body::empty())
|
||||
.expect("request"),
|
||||
)
|
||||
.await
|
||||
.expect("response");
|
||||
assert_ne!(
|
||||
response.status(),
|
||||
StatusCode::NOT_FOUND,
|
||||
"{method} {path} 应显式挂到 Rust 3000 单入口边界",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user