1- use std:: { convert:: Infallible , net:: SocketAddr , path:: PathBuf , str:: FromStr , sync:: Arc } ;
1+ use std:: convert:: Infallible ;
2+ use std:: net:: SocketAddr ;
3+ use std:: path:: PathBuf ;
4+ use std:: str:: FromStr ;
5+ use std:: sync:: Arc ;
26
37use anyhow:: Result ;
48use http_body_util:: { BodyExt , Full } ;
@@ -7,28 +11,32 @@ use hyper::{
711 server:: conn:: http1,
812 Method , Request , Response ,
913} ;
10- use hyper_util:: { rt:: TokioIo , service:: TowerToHyperService } ;
14+ use hyper_util:: rt:: TokioIo ;
15+ use hyper_util:: service:: TowerToHyperService ;
1116use tokio:: net:: TcpListener ;
1217use tokio:: runtime:: Runtime ;
1318use tower:: ServiceBuilder ;
1419use tower_http:: cors:: { Any , CorsLayer } ;
15- use tracing:: info;
1620
21+ use crate :: config:: Config ;
1722use crate :: plugin:: ExternalFunctions ;
1823
19- pub struct Server { }
24+ pub struct Server {
25+ config : Config ,
26+ }
2027
2128impl Server {
22- pub async fn run ( rt : Arc < Runtime > ) -> Result < ( ) > {
23- info ! ( "Initializing server" ) ;
29+ pub fn new ( config : Config ) -> Self {
30+ Server { config }
31+ }
2432
25- let addr = SocketAddr :: from ( ( [ 0 , 0 , 0 , 0 ] , 3000 ) ) ;
33+ pub async fn run ( self , rt : Arc < Runtime > ) -> Result < ( ) > {
34+ let addr = SocketAddr :: from ( ( self . config . host , self . config . port ) ) ;
2635 let listener = TcpListener :: bind ( addr) . await ?;
2736 let functions = Arc :: new ( ExternalFunctions :: new ( ) ) ;
2837 let plugin_library = PathBuf :: from_str ( "./target/debug/libfile_explorer.dylib" ) . unwrap ( ) ;
2938 let config = PathBuf :: from_str ( "./config.toml" ) . unwrap ( ) ;
3039 let handle = Arc :: new ( rt. handle ( ) . to_owned ( ) ) ;
31- let local_ip = local_ip_address:: local_ip ( ) ;
3240
3341 unsafe {
3442 functions
@@ -37,9 +45,6 @@ impl Server {
3745 . expect ( "Function loading failed" ) ;
3846 }
3947
40- info ! ( %addr, "Server Listening" ) ;
41- info ! ( ?local_ip, "Local Network" ) ;
42-
4348 loop {
4449 let ( stream, _) = listener. accept ( ) . await ?;
4550 let io = TokioIo :: new ( stream) ;
0 commit comments