File tree Expand file tree Collapse file tree 4 files changed +20
-8
lines changed
Expand file tree Collapse file tree 4 files changed +20
-8
lines changed Original file line number Diff line number Diff line change 11host = " 127.0.0.1"
22port = " 7878"
3+ cors = true
34
45[file-explorer ]
56path = " ./"
Original file line number Diff line number Diff line change @@ -20,6 +20,19 @@ pub struct StartOpt {
2020 /// Port to bind the server
2121 #[ clap( short = 'p' , long, default_value = "7878" ) ]
2222 pub port : u16 ,
23+ /// Enable CORS with a permissive policy
24+ #[ clap( long, default_value = "false" ) ]
25+ pub cors : bool ,
26+ }
27+
28+ impl From < & StartOpt > for Config {
29+ fn from ( val : & StartOpt ) -> Self {
30+ Config {
31+ host : val. host ,
32+ port : val. port ,
33+ cors : val. cors ,
34+ }
35+ }
2336}
2437
2538impl StartOpt {
@@ -29,10 +42,7 @@ impl StartOpt {
2942 . thread_name ( THREAD_NAME )
3043 . build ( ) ?;
3144 let rt = Arc :: new ( rt) ;
32- let config = Config {
33- host : self . host ,
34- port : self . port ,
35- } ;
45+ let config: Config = self . into ( ) ;
3646 let server = Server :: new ( config) ;
3747
3848 rt. block_on ( async {
Original file line number Diff line number Diff line change @@ -5,4 +5,6 @@ pub struct Config {
55 pub host : IpAddr ,
66 /// The port to bind to.
77 pub port : u16 ,
8+ /// Enable CORS with a permissive policy.
9+ pub cors : bool ,
810}
Original file line number Diff line number Diff line change @@ -34,15 +34,14 @@ impl Server {
3434 let addr = SocketAddr :: from ( ( self . config . host , self . config . port ) ) ;
3535 let listener = TcpListener :: bind ( addr) . await ?;
3636 let functions = Arc :: new ( ExternalFunctions :: new ( ) ) ;
37- let plugin_library = PathBuf :: from_str ( "./target/debug/libfile_explorer.dylib" ) . unwrap ( ) ;
38- let config = PathBuf :: from_str ( "./config.toml" ) . unwrap ( ) ;
37+ let plugin_library = PathBuf :: from_str ( "./target/debug/libfile_explorer.dylib" ) ? ;
38+ let config = PathBuf :: from_str ( "./config.toml" ) ? ;
3939 let handle = Arc :: new ( rt. handle ( ) . to_owned ( ) ) ;
4040
4141 unsafe {
4242 functions
4343 . load ( Arc :: clone ( & handle) , config, plugin_library)
44- . await
45- . expect ( "Function loading failed" ) ;
44+ . await ?;
4645 }
4746
4847 loop {
You can’t perform that action at this time.
0 commit comments