Move api_root to global scope
This commit is contained in:
parent
d3323ac7ac
commit
c474d7b454
1 changed files with 43 additions and 43 deletions
|
|
@ -592,25 +592,7 @@ async fn update_session_ratelimits(
|
||||||
Ok(Json(EmptyJsonResponse {}))
|
Ok(Json(EmptyJsonResponse {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HttpApi {
|
async fn api_root(parts: Parts) -> impl IntoResponse {
|
||||||
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 {
|
|
||||||
// If browser, and webui enabled, redirect to web
|
// If browser, and webui enabled, redirect to web
|
||||||
#[cfg(feature = "webui")]
|
#[cfg(feature = "webui")]
|
||||||
{
|
{
|
||||||
|
|
@ -651,7 +633,25 @@ impl HttpApi {
|
||||||
"version": env!("CARGO_PKG_VERSION"),
|
"version": env!("CARGO_PKG_VERSION"),
|
||||||
})),
|
})),
|
||||||
).into_response()
|
).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()
|
let mut app = Router::new()
|
||||||
.route("/", get(api_root))
|
.route("/", get(api_root))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue