use std::sync::Arc;
use axum::routing::{get, put};
use axum::Router;
pub mod endpoints;
pub mod http_proxy;
pub mod registry;
pub mod state;
pub mod tls;
pub mod types;
pub use endpoints::{
handle_api_download, handle_api_publish, handle_api_search, handle_config, handle_index_1char,
handle_index_2char, handle_index_3char, handle_index_4plus,
};
pub use http_proxy::{handle_proxy_connection, HttpProxyState};
pub use registry::{
build_registry, AnyRegistry, BuiltRegistry, DynRegistry, Registry, RegistryBuildOptions,
RegistrySpec,
};
pub use state::{GenericProxyState, MitmCa, RegistryState};
pub use tls::generate_self_signed_cert;
pub fn build_registry_router<S: RegistryState + Clone + Send + Sync + 'static>(
state: Arc<S>,
) -> Router {
Router::new()
.route("/config.json", get(handle_config::<S>))
.route("/1/{name}", get(handle_index_1char::<S>))
.route("/2/{name}", get(handle_index_2char::<S>))
.route("/3/{first_char}/{name}", get(handle_index_3char::<S>))
.route(
"/{first_two}/{second_two}/{name}",
get(handle_index_4plus::<S>),
)
.route("/api/v1/crates", get(handle_api_search::<S>))
.route("/api/v1/crates/new", put(handle_api_publish::<S>))
.route(
"/api/v1/crates/{crate_name}/{version}/download",
get(handle_api_download::<S>),
)
.with_state(state)
}