@@ -201,6 +201,10 @@ impl AppConfig {
201201 ) )
202202 . add_source ( File :: with_name ( "config.yaml" ) . required ( false ) )
203203 . add_source ( Environment :: with_prefix ( "DICOM_RST" ) . separator ( "_" ) )
204+ . set_override_option (
205+ "server.http.base-path" ,
206+ std:: env:: var ( "DICOM_RST_SERVER_HTTP_BASE_PATH" ) . ok ( ) ,
207+ ) ?
204208 . build ( ) ?
205209 . try_deserialize ( )
206210 }
@@ -232,6 +236,27 @@ pub struct HttpServerConfig {
232236 pub max_upload_size : usize ,
233237 pub request_timeout : u64 ,
234238 pub graceful_shutdown : bool ,
239+ pub base_path : String ,
240+ }
241+
242+ impl HttpServerConfig {
243+ const WILDCARD_ADDRESSES : [ & ' static str ; 3 ] =
244+ [ "0.0.0.0" , "::" , "0000:0000:0000:0000:0000:0000:0000:0000" ] ;
245+
246+ pub fn base_url ( & self ) -> Result < url:: Url , url:: ParseError > {
247+ let origin = format ! ( "http://{}:{}" , self . interface, self . port) ;
248+ let mut url = url:: Url :: parse ( & origin) ?;
249+
250+ if url
251+ . host ( )
252+ . is_some_and ( |host| Self :: WILDCARD_ADDRESSES . contains ( & host. to_string ( ) . as_str ( ) ) )
253+ {
254+ url. set_host ( Some ( "127.0.0.1" ) ) ?;
255+ }
256+ let url = url. join ( & self . base_path ) ?;
257+
258+ Ok ( url)
259+ }
235260}
236261
237262impl Default for HttpServerConfig {
@@ -242,6 +267,7 @@ impl Default for HttpServerConfig {
242267 graceful_shutdown : true ,
243268 max_upload_size : 50_000_000 , // 50 MB
244269 request_timeout : 60_000 , // 1 min
270+ base_path : String :: from ( "/" ) ,
245271 }
246272 }
247273}
0 commit comments