Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/cocoindex/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 42 additions & 32 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}