anvilsign in

collin/anvil

1//! HTTP server for anvil: the web UI and the smart-HTTP git endpoints
2//! (`/<owner>/<repo>.git/info/refs`, `/git-upload-pack`, `/git-receive-pack`),
3//! plus cookie-session auth.
4
5// Handlers return `Result<_, Response>` — the idiomatic axum pattern where the
6// error arm is a ready-made HTTP response (404/500/redirect). `Response` is
7// intrinsically large, so `result_large_err` fires across the crate; the
8// pattern is intentional and the responses are never hot-path allocated en masse.
9#![allow(clippy::result_large_err)]
10
11use anvil_core::{
12 App,
13 Result,
14};
15use axum::{
16 Router,
17 routing::{
18 get,
19 post,
20 },
21};
22
23pub mod auth;
24pub mod git_http;
25pub mod ui;
26
27/// Build the application router.
28pub fn router(app: App) -> Router {
29 let mut router = Router::new()
30 .route("/-/healthz", get(healthz))
31 .route("/-/login", get(auth::login_form).post(auth::login_submit))
32 .route("/-/logout", post(auth::logout));
33 router = ui::routes(router); // web UI, including `/`
34 router = git_http::routes(router); // smart-HTTP git endpoints
35 router.with_state(app)
36}
37
38/// Bind to the configured HTTP address and serve until shutdown.
39pub async fn serve(app: App) -> Result<()> {
40 let listen = app.config.http.listen.clone();
41 let router = router(app);
42
43 let listener = tokio::net::TcpListener::bind(&listen).await?;
44 tracing::info!("anvil web server listening on http://{listen}");
45 axum::serve(listener, router).await?;
46 Ok(())
47}
48
49async fn healthz() -> &'static str {
50 "ok"
51}