mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
add localhost support to the http server (#1939)
This commit is contained in:
committed by
Aiden McClelland
parent
45a6a930c9
commit
6cea0139d1
@@ -36,6 +36,8 @@ async fn setup_or_init(cfg_path: Option<PathBuf>) -> Result<(), Error> {
|
|||||||
let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?;
|
let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?;
|
||||||
let embassy_fqdn: ResourceFqdn = "pureos.local".parse()?;
|
let embassy_fqdn: ResourceFqdn = "pureos.local".parse()?;
|
||||||
|
|
||||||
|
let localhost_fqdn = ResourceFqdn::LocalHost;
|
||||||
|
|
||||||
let install_ui_handler = install_ui_file_router(ctx.clone()).await?;
|
let install_ui_handler = install_ui_file_router(ctx.clone()).await?;
|
||||||
|
|
||||||
let mut install_http_server =
|
let mut install_http_server =
|
||||||
@@ -44,7 +46,11 @@ async fn setup_or_init(cfg_path: Option<PathBuf>) -> Result<(), Error> {
|
|||||||
.add_svc_handler_mapping(embassy_ip_fqdn, install_ui_handler.clone())
|
.add_svc_handler_mapping(embassy_ip_fqdn, install_ui_handler.clone())
|
||||||
.await?;
|
.await?;
|
||||||
install_http_server
|
install_http_server
|
||||||
.add_svc_handler_mapping(embassy_fqdn, install_ui_handler)
|
.add_svc_handler_mapping(embassy_fqdn, install_ui_handler.clone())
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
install_http_server
|
||||||
|
.add_svc_handler_mapping(localhost_fqdn, install_ui_handler.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
tokio::time::sleep(Duration::from_secs(1)).await; // let the record state that I hate this
|
tokio::time::sleep(Duration::from_secs(1)).await; // let the record state that I hate this
|
||||||
@@ -71,6 +77,7 @@ async fn setup_or_init(cfg_path: Option<PathBuf>) -> Result<(), Error> {
|
|||||||
let embassy_ip = get_current_ip(ctx.ethernet_interface.to_owned()).await?;
|
let embassy_ip = get_current_ip(ctx.ethernet_interface.to_owned()).await?;
|
||||||
let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?;
|
let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?;
|
||||||
let embassy_fqdn: ResourceFqdn = "embassy.local".parse()?;
|
let embassy_fqdn: ResourceFqdn = "embassy.local".parse()?;
|
||||||
|
let localhost_fqdn = ResourceFqdn::LocalHost;
|
||||||
|
|
||||||
let setup_ui_handler = setup_ui_file_router(ctx.clone()).await?;
|
let setup_ui_handler = setup_ui_file_router(ctx.clone()).await?;
|
||||||
|
|
||||||
@@ -80,7 +87,11 @@ async fn setup_or_init(cfg_path: Option<PathBuf>) -> Result<(), Error> {
|
|||||||
.add_svc_handler_mapping(embassy_ip_fqdn, setup_ui_handler.clone())
|
.add_svc_handler_mapping(embassy_ip_fqdn, setup_ui_handler.clone())
|
||||||
.await?;
|
.await?;
|
||||||
setup_http_server
|
setup_http_server
|
||||||
.add_svc_handler_mapping(embassy_fqdn, setup_ui_handler)
|
.add_svc_handler_mapping(embassy_fqdn, setup_ui_handler.clone())
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
setup_http_server
|
||||||
|
.add_svc_handler_mapping(localhost_fqdn, setup_ui_handler.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
tokio::time::sleep(Duration::from_secs(1)).await; // let the record state that I hate this
|
tokio::time::sleep(Duration::from_secs(1)).await; // let the record state that I hate this
|
||||||
@@ -187,6 +198,8 @@ async fn inner_main(cfg_path: Option<PathBuf>) -> Result<Option<Shutdown>, Error
|
|||||||
let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?;
|
let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?;
|
||||||
let embassy_fqdn: ResourceFqdn = "embassy.local".parse()?;
|
let embassy_fqdn: ResourceFqdn = "embassy.local".parse()?;
|
||||||
|
|
||||||
|
let localhost_fqdn = ResourceFqdn::LocalHost;
|
||||||
|
|
||||||
let diag_ui_handler = diag_ui_file_router(ctx.clone()).await?;
|
let diag_ui_handler = diag_ui_file_router(ctx.clone()).await?;
|
||||||
|
|
||||||
let mut diag_http_server =
|
let mut diag_http_server =
|
||||||
@@ -195,7 +208,11 @@ async fn inner_main(cfg_path: Option<PathBuf>) -> Result<Option<Shutdown>, Error
|
|||||||
.add_svc_handler_mapping(embassy_ip_fqdn, diag_ui_handler.clone())
|
.add_svc_handler_mapping(embassy_ip_fqdn, diag_ui_handler.clone())
|
||||||
.await?;
|
.await?;
|
||||||
diag_http_server
|
diag_http_server
|
||||||
.add_svc_handler_mapping(embassy_fqdn, diag_ui_handler)
|
.add_svc_handler_mapping(embassy_fqdn, diag_ui_handler.clone())
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
diag_http_server
|
||||||
|
.add_svc_handler_mapping(localhost_fqdn, diag_ui_handler.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let shutdown = ctx.shutdown.subscribe().recv().await.unwrap();
|
let shutdown = ctx.shutdown.subscribe().recv().await.unwrap();
|
||||||
|
|||||||
@@ -118,12 +118,11 @@ impl NetController {
|
|||||||
let ip = get_current_ip(rpc_ctx.ethernet_interface.to_owned()).await?;
|
let ip = get_current_ip(rpc_ctx.ethernet_interface.to_owned()).await?;
|
||||||
|
|
||||||
let embassy_tor_addr = get_embassyd_tor_addr(rpc_ctx.clone()).await?;
|
let embassy_tor_addr = get_embassyd_tor_addr(rpc_ctx.clone()).await?;
|
||||||
|
|
||||||
let embassy_tor_fqdn: ResourceFqdn = embassy_tor_addr.parse()?;
|
let embassy_tor_fqdn: ResourceFqdn = embassy_tor_addr.parse()?;
|
||||||
|
|
||||||
let host_name_fqdn: ResourceFqdn = host_name.parse()?;
|
let host_name_fqdn: ResourceFqdn = host_name.parse()?;
|
||||||
let ip_fqdn: ResourceFqdn = ip.parse()?;
|
let ip_fqdn: ResourceFqdn = ip.parse()?;
|
||||||
|
|
||||||
|
let localhost_fqdn = ResourceFqdn::LocalHost;
|
||||||
|
|
||||||
let handler: HttpHandler =
|
let handler: HttpHandler =
|
||||||
crate::net::static_server::main_ui_server_router(rpc_ctx.clone()).await?;
|
crate::net::static_server::main_ui_server_router(rpc_ctx.clone()).await?;
|
||||||
@@ -146,6 +145,12 @@ impl NetController {
|
|||||||
.add_handle(80, ip_fqdn.clone(), handler.clone(), false)
|
.add_handle(80, ip_fqdn.clone(), handler.clone(), false)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
rpc_ctx
|
||||||
|
.net_controller
|
||||||
|
.proxy
|
||||||
|
.add_handle(80, localhost_fqdn.clone(), handler.clone(), false)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ pub enum ResourceFqdn {
|
|||||||
root: String,
|
root: String,
|
||||||
tld: Tld,
|
tld: Tld,
|
||||||
},
|
},
|
||||||
|
LocalHost
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ResourceFqdn {
|
impl fmt::Display for ResourceFqdn {
|
||||||
@@ -50,6 +51,7 @@ impl fmt::Display for ResourceFqdn {
|
|||||||
} => {
|
} => {
|
||||||
write!(f, "{}", full_uri)
|
write!(f, "{}", full_uri)
|
||||||
}
|
}
|
||||||
|
ResourceFqdn::LocalHost => write!(f, "localhost")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,6 +78,10 @@ impl FromStr for ResourceFqdn {
|
|||||||
|
|
||||||
fn from_str(input: &str) -> Result<ResourceFqdn, Self::Err> {
|
fn from_str(input: &str) -> Result<ResourceFqdn, Self::Err> {
|
||||||
|
|
||||||
|
if input == "localhost" {
|
||||||
|
return Ok(ResourceFqdn::LocalHost);
|
||||||
|
}
|
||||||
|
|
||||||
if let Ok(ip) = input.parse::<IpAddr>() {
|
if let Ok(ip) = input.parse::<IpAddr>() {
|
||||||
return Ok(ResourceFqdn::IpAddr(ip));
|
return Ok(ResourceFqdn::IpAddr(ip));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,6 +124,13 @@ impl ProxyController {
|
|||||||
error!("server io error: {}", e);
|
error!("server io error: {}", e);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
ResourceFqdn::LocalHost => {
|
||||||
|
if let Err(e) =
|
||||||
|
Self::tunnel(upgraded, "localhost".to_string()).await
|
||||||
|
{
|
||||||
|
error!("server io error: {}", e);
|
||||||
|
};
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Err(e) => error!("upgrade error: {}", e),
|
Err(e) => error!("upgrade error: {}", e),
|
||||||
}
|
}
|
||||||
@@ -224,6 +231,12 @@ impl ProxyControllerInner {
|
|||||||
root,
|
root,
|
||||||
tld: _,
|
tld: _,
|
||||||
} => self.ssl_manager.certificate_for(&root, &pkg_id).await?,
|
} => self.ssl_manager.certificate_for(&root, &pkg_id).await?,
|
||||||
|
ResourceFqdn::LocalHost => {
|
||||||
|
return Err(Error::new(
|
||||||
|
eyre!("ssl not supported for localhost"),
|
||||||
|
crate::ErrorKind::Network,
|
||||||
|
))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.vhosts
|
self.vhosts
|
||||||
|
|||||||
Reference in New Issue
Block a user