@@ -11,11 +11,12 @@ use axum::{
1111 extract:: { MatchedPath , State } ,
1212 http:: { HeaderMap , Request } ,
1313 response:: { IntoResponse , Response } ,
14- routing:: post,
14+ routing:: { get , post} ,
1515} ;
1616use serde:: { Deserialize , Serialize } ;
1717use serde_json:: Value ;
1818use tokio:: sync:: mpsc:: UnboundedSender ;
19+ use tower_http:: cors:: { Any , CorsLayer } ;
1920use tower_http:: { classify:: ServerErrorsFailureClass , trace:: TraceLayer } ;
2021use tracing:: { Span , info_span} ;
2122#[ cfg( feature = "swagger" ) ]
@@ -211,18 +212,53 @@ async fn stop_all_actors(State(state): State<Arc<AppState>>) -> impl IntoRespons
211212 ( axum:: http:: StatusCode :: OK , "Actors Stopped!" )
212213}
213214
215+ #[ derive( Serialize , ToSchema ) ]
216+ struct StatusResponse {
217+ actors : Vec < String > ,
218+ loaded_libs : Vec < String > ,
219+ }
220+ #[ cfg_attr( feature="swagger" , utoipa:: path(
221+ get,
222+ path = "/status" ,
223+ responses(
224+ ( status = 200 , description = "Status of the node" , body = StatusResponse )
225+ )
226+ ) ) ]
227+ async fn get_status ( State ( state) : State < Arc < AppState > > ) -> impl IntoResponse {
228+ let ( tx, rx) = tokio:: sync:: oneshot:: channel ( ) ;
229+ state
230+ . tx
231+ . send ( JobControllerReq :: GetStatus { resp_tx : tx } )
232+ . unwrap ( ) ;
233+ let result = rx. await . unwrap ( ) ;
234+ (
235+ axum:: http:: StatusCode :: OK ,
236+ Json ( StatusResponse {
237+ actors : result. actors ,
238+ loaded_libs : result. loaded_libs ,
239+ } ) ,
240+ )
241+ }
242+
214243#[ cfg( feature = "swagger" ) ]
215244#[ derive( OpenApi ) ]
216- #[ openapi( paths( start_actor, actor_added, register_lib, stop_all_actors) ) ]
245+ #[ openapi( paths( start_actor, actor_added, register_lib, stop_all_actors, get_status ) ) ]
217246struct ApiDoc ;
218247
219248pub async fn webserver ( job_control_tx : UnboundedSender < JobControllerReq > , port : u16 ) {
220249 let state = Arc :: new ( AppState { tx : job_control_tx } ) ;
221250 let app = Router :: new ( )
251+ . route ( "/status" , get ( get_status) )
222252 . route ( "/start_actor" , post ( start_actor) )
223253 . route ( "/actor_added" , post ( actor_added) )
224254 . route ( "/register_lib" , post ( register_lib) )
225255 . route ( "/stop_all_actors" , post ( stop_all_actors) )
256+ . layer (
257+ CorsLayer :: new ( )
258+ . allow_origin ( Any ) // allow all origins
259+ . allow_methods ( Any ) // allow all methods (GET, POST, etc.)
260+ . allow_headers ( Any ) , // allow all headers
261+ )
226262 . with_state ( state)
227263 . layer (
228264 TraceLayer :: new_for_http ( )
0 commit comments