Skip to content

Commit 6437f09

Browse files
authored
feat(port): use localhost:9876/cocoindex as default prefix (#434)
* feat(port): use `localhost:9876/cocoindex` as default prefix * chore: change port to `49344` (`0xc0c0`)
1 parent 5e1ac38 commit 6437f09

File tree

2 files changed

+43
-33
lines changed

2 files changed

+43
-33
lines changed

python/cocoindex/setting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ServerSettings:
4747
"""Settings for the cocoindex server."""
4848

4949
# The address to bind the server to.
50-
address: str = "127.0.0.1:8080"
50+
address: str = "127.0.0.1:49344"
5151

5252
# The origins of the clients (e.g. CocoInsight UI) to allow CORS from.
5353
cors_origins: list[str] | None = None

src/server.rs

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,44 +37,54 @@ pub async fn init_server(
3737
.allow_headers([axum::http::header::CONTENT_TYPE]);
3838
}
3939
let app = Router::new()
40-
.route("/api/flows", routing::get(service::flows::list_flows))
4140
.route(
42-
"/api/flows/:flowInstName",
43-
routing::get(service::flows::get_flow_spec),
41+
"/cocoindex",
42+
routing::get(|| async { "CocoIndex is running!" }),
4443
)
45-
.route(
46-
"/api/flows/:flowInstName/schema",
47-
routing::get(service::flows::get_flow_schema),
48-
)
49-
.route(
50-
"/api/flows/:flowInstName/keys",
51-
routing::get(service::flows::get_keys),
52-
)
53-
.route(
54-
"/api/flows/:flowInstName/data",
55-
routing::get(service::flows::evaluate_data),
56-
)
57-
.route(
58-
"/api/flows/:flowInstName/update",
59-
routing::post(service::flows::update),
60-
)
61-
.route(
62-
"/api/flows/:flowInstName/search",
63-
routing::get(service::search::search),
64-
)
65-
.layer(
66-
ServiceBuilder::new()
67-
.layer(TraceLayer::new_for_http())
68-
.layer(cors),
69-
)
70-
.with_state(lib_context.clone());
44+
.nest(
45+
"/cocoindex/api",
46+
Router::new()
47+
.route("/flows", routing::get(service::flows::list_flows))
48+
.route(
49+
"/flows/:flowInstName",
50+
routing::get(service::flows::get_flow_spec),
51+
)
52+
.route(
53+
"/flows/:flowInstName/schema",
54+
routing::get(service::flows::get_flow_schema),
55+
)
56+
.route(
57+
"/flows/:flowInstName/keys",
58+
routing::get(service::flows::get_keys),
59+
)
60+
.route(
61+
"/flows/:flowInstName/data",
62+
routing::get(service::flows::evaluate_data),
63+
)
64+
.route(
65+
"/flows/:flowInstName/update",
66+
routing::post(service::flows::update),
67+
)
68+
.route(
69+
"/flows/:flowInstName/search",
70+
routing::get(service::search::search),
71+
)
72+
.layer(
73+
ServiceBuilder::new()
74+
.layer(TraceLayer::new_for_http())
75+
.layer(cors),
76+
)
77+
.with_state(lib_context.clone()),
78+
);
7179

72-
// run our app with hyper, listening globally on port 3000
7380
let listener = tokio::net::TcpListener::bind(&settings.address)
7481
.await
75-
.unwrap();
82+
.context(format!("Failed to bind to address: {}", settings.address))?;
7683

77-
println!("Server running at http://{}/", settings.address);
84+
println!(
85+
"Server running at http://{}/cocoindex",
86+
listener.local_addr()?
87+
);
7888
let serve_fut = async { axum::serve(listener, app).await.unwrap() };
7989
Ok(serve_fut.boxed())
8090
}

0 commit comments

Comments
 (0)