@@ -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