diff --git a/python/cocoindex/setting.py b/python/cocoindex/setting.py index 781e3fd..00c8545 100644 --- a/python/cocoindex/setting.py +++ b/python/cocoindex/setting.py @@ -47,7 +47,7 @@ class ServerSettings: """Settings for the cocoindex server.""" # The address to bind the server to. - address: str = "127.0.0.1:8080" + address: str = "127.0.0.1:49344" # The origins of the clients (e.g. CocoInsight UI) to allow CORS from. cors_origins: list[str] | None = None diff --git a/src/server.rs b/src/server.rs index 03feb3b..ef2c185 100644 --- a/src/server.rs +++ b/src/server.rs @@ -37,44 +37,54 @@ pub async fn init_server( .allow_headers([axum::http::header::CONTENT_TYPE]); } let app = Router::new() - .route("/api/flows", routing::get(service::flows::list_flows)) .route( - "/api/flows/:flowInstName", - routing::get(service::flows::get_flow_spec), + "/cocoindex", + routing::get(|| async { "CocoIndex is running!" }), ) - .route( - "/api/flows/:flowInstName/schema", - routing::get(service::flows::get_flow_schema), - ) - .route( - "/api/flows/:flowInstName/keys", - routing::get(service::flows::get_keys), - ) - .route( - "/api/flows/:flowInstName/data", - routing::get(service::flows::evaluate_data), - ) - .route( - "/api/flows/:flowInstName/update", - routing::post(service::flows::update), - ) - .route( - "/api/flows/:flowInstName/search", - routing::get(service::search::search), - ) - .layer( - ServiceBuilder::new() - .layer(TraceLayer::new_for_http()) - .layer(cors), - ) - .with_state(lib_context.clone()); + .nest( + "/cocoindex/api", + Router::new() + .route("/flows", routing::get(service::flows::list_flows)) + .route( + "/flows/:flowInstName", + routing::get(service::flows::get_flow_spec), + ) + .route( + "/flows/:flowInstName/schema", + routing::get(service::flows::get_flow_schema), + ) + .route( + "/flows/:flowInstName/keys", + routing::get(service::flows::get_keys), + ) + .route( + "/flows/:flowInstName/data", + routing::get(service::flows::evaluate_data), + ) + .route( + "/flows/:flowInstName/update", + routing::post(service::flows::update), + ) + .route( + "/flows/:flowInstName/search", + routing::get(service::search::search), + ) + .layer( + ServiceBuilder::new() + .layer(TraceLayer::new_for_http()) + .layer(cors), + ) + .with_state(lib_context.clone()), + ); - // run our app with hyper, listening globally on port 3000 let listener = tokio::net::TcpListener::bind(&settings.address) .await - .unwrap(); + .context(format!("Failed to bind to address: {}", settings.address))?; - println!("Server running at http://{}/", settings.address); + println!( + "Server running at http://{}/cocoindex", + listener.local_addr()? + ); let serve_fut = async { axum::serve(listener, app).await.unwrap() }; Ok(serve_fut.boxed()) }