Move api_root to global scope

This commit is contained in:
Igor Katson 2025-01-14 10:05:23 +00:00
parent d3323ac7ac
commit c474d7b454
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5

View file

@ -592,25 +592,7 @@ async fn update_session_ratelimits(
Ok(Json(EmptyJsonResponse {}))
}
impl HttpApi {
pub fn new(api: Api, opts: Option<HttpApiOptions>) -> Self {
Self {
api,
opts: opts.unwrap_or_default(),
}
}
/// Run the HTTP server forever on the given address.
/// If read_only is passed, no state-modifying methods will be exposed.
#[inline(never)]
pub fn make_http_api_and_run(
self,
listener: TcpListener,
upnp_router: Option<Router>,
) -> BoxFuture<'static, anyhow::Result<()>> {
let state = Arc::new(self);
let api_root = move |parts: Parts| async move {
async fn api_root(parts: Parts) -> impl IntoResponse {
// If browser, and webui enabled, redirect to web
#[cfg(feature = "webui")]
{
@ -651,7 +633,25 @@ impl HttpApi {
"version": env!("CARGO_PKG_VERSION"),
})),
).into_response()
};
}
impl HttpApi {
pub fn new(api: Api, opts: Option<HttpApiOptions>) -> Self {
Self {
api,
opts: opts.unwrap_or_default(),
}
}
/// Run the HTTP server forever on the given address.
/// If read_only is passed, no state-modifying methods will be exposed.
#[inline(never)]
pub fn make_http_api_and_run(
self,
listener: TcpListener,
upnp_router: Option<Router>,
) -> BoxFuture<'static, anyhow::Result<()>> {
let state = Arc::new(self);
let mut app = Router::new()
.route("/", get(api_root))