♻️ refactor: custom servers won't create a file server module.
parent
6c826b0cc5
commit
b018f16794
|
@ -73,7 +73,7 @@ pub mod load_toml;
|
|||
use errors::ServerError;
|
||||
|
||||
pub struct State {
|
||||
file_server: file_server::FileServer,
|
||||
// file_server: file_server::FileServer,
|
||||
config: Config,
|
||||
client: Client,
|
||||
}
|
||||
|
@ -179,13 +179,6 @@ SH: Send + FnMut () -> H
|
|||
let (req_id, parts) = (wrapped_req.id, wrapped_req.req);
|
||||
|
||||
debug! ("Handling request {}", req_id);
|
||||
/*
|
||||
let response = state.file_server.serve_all (
|
||||
parts.method,
|
||||
&parts.uri,
|
||||
&parts.headers,
|
||||
).await?;
|
||||
*/
|
||||
|
||||
let f = handler (parts);
|
||||
let response = f.await?;
|
||||
|
@ -246,6 +239,9 @@ impl ConfigFile {
|
|||
|
||||
#[derive (Default)]
|
||||
pub struct Config {
|
||||
/// The name of our `ptth_server` instance
|
||||
pub name: String,
|
||||
|
||||
/// URL of the PTTH relay server that ptth_server should connect to
|
||||
pub relay_url: String,
|
||||
|
||||
|
@ -294,6 +290,8 @@ impl Builder {
|
|||
}
|
||||
}
|
||||
|
||||
/// Runs a `ptth_server` instance with the built-in file server module
|
||||
|
||||
pub async fn run_server (
|
||||
config_file: ConfigFile,
|
||||
shutdown_oneshot: oneshot::Receiver <()>,
|
||||
|
@ -302,19 +300,34 @@ pub async fn run_server (
|
|||
)
|
||||
-> Result <(), ServerError>
|
||||
{
|
||||
let metrics_interval = Arc::new (arc_swap::ArcSwap::default ());
|
||||
let interval_writer = Arc::clone (&metrics_interval);
|
||||
tokio::spawn (async move {
|
||||
file_server::metrics::Interval::monitor (interval_writer).await;
|
||||
});
|
||||
|
||||
let file_server = file_server::FileServer::new (
|
||||
config_file.file_server_root.clone (),
|
||||
&asset_root.clone ().unwrap_or_else (PathBuf::new),
|
||||
config_file.name.clone (),
|
||||
metrics_interval,
|
||||
hidden_path.clone (),
|
||||
)?;
|
||||
let file_server = Arc::new (file_server);
|
||||
|
||||
let state = Arc::new (State::new (
|
||||
config_file,
|
||||
hidden_path,
|
||||
asset_root,
|
||||
)?);
|
||||
|
||||
let state_2 = Arc::clone (&state);
|
||||
let file_server_2 = Arc::clone (&file_server);
|
||||
|
||||
let mut spawn_handler = || {
|
||||
let state = Arc::clone (&state_2);
|
||||
let file_server = Arc::clone (&file_server);
|
||||
|
||||
|req: http_serde::RequestParts| async move {
|
||||
Ok (state.file_server.serve_all (req.method, &req.uri, &req.headers).await?)
|
||||
Ok (file_server.serve_all (req.method, &req.uri, &req.headers).await?)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -350,22 +363,9 @@ impl State {
|
|||
.connect_timeout (Duration::from_secs (30))
|
||||
.build ().map_err (ServerError::CantBuildHttpClient)?;
|
||||
|
||||
let metrics_interval = Arc::new (ArcSwap::default ());
|
||||
|
||||
let interval_writer = Arc::clone (&metrics_interval);
|
||||
tokio::spawn (async move {
|
||||
file_server::metrics::Interval::monitor (interval_writer).await;
|
||||
});
|
||||
|
||||
let state = State {
|
||||
file_server: file_server::FileServer::new (
|
||||
config_file.file_server_root,
|
||||
&asset_root,
|
||||
config_file.name,
|
||||
metrics_interval,
|
||||
hidden_path,
|
||||
)?,
|
||||
config: Config {
|
||||
name: config_file.name,
|
||||
relay_url: config_file.relay_url,
|
||||
throttle_upload: config_file.throttle_upload,
|
||||
},
|
||||
|
@ -408,7 +408,7 @@ impl State {
|
|||
|
||||
debug! ("http_listen");
|
||||
|
||||
let req_req = state.client.get (&format! ("{}/http_listen/{}", state.config.relay_url, state.file_server.metrics_startup.server_name))
|
||||
let req_req = state.client.get (&format! ("{}/http_listen/{}", state.config.relay_url, state.config.name))
|
||||
.timeout (Duration::from_secs (30))
|
||||
.send ();
|
||||
|
||||
|
|
Loading…
Reference in New Issue