feat: move web routes to /

main
Jef Roosens 2025-03-30 16:58:01 +02:00
parent 82ccad196c
commit bf132f93dc
No known key found for this signature in database
GPG Key ID: 21FD3D77D56BAF49
3 changed files with 8 additions and 10 deletions

View File

@ -10,8 +10,7 @@ use axum::{
extract::Request, extract::Request,
http::StatusCode, http::StatusCode,
middleware::Next, middleware::Next,
response::{IntoResponse, Redirect, Response}, response::{IntoResponse, Response},
routing::get,
Router, Router,
}; };
use http_body_util::BodyExt; use http_body_util::BodyExt;
@ -26,11 +25,10 @@ pub struct Context {
pub fn app(ctx: Context) -> Router { pub fn app(ctx: Context) -> Router {
Router::new() Router::new()
.merge(gpodder::router(ctx.clone())) .merge(gpodder::router(ctx.clone()))
.merge(web::router(ctx.clone()))
.nest("/static", r#static::router()) .nest("/static", r#static::router())
.nest("/_", web::router(ctx.clone()))
.route("/", get(|| async { Redirect::to("/_") }))
.layer(axum::middleware::from_fn(header_logger)) .layer(axum::middleware::from_fn(header_logger))
.layer(axum::middleware::from_fn(body_logger)) // .layer(axum::middleware::from_fn(body_logger))
.layer(TraceLayer::new_for_http()) .layer(TraceLayer::new_for_http())
.with_state(ctx) .with_state(ctx)
} }
@ -45,7 +43,7 @@ async fn header_logger(request: Request, next: Next) -> Response {
res res
} }
async fn body_logger(request: Request, next: Next) -> Response { async fn _body_logger(request: Request, next: Next) -> Response {
let (parts, body) = request.into_parts(); let (parts, body) = request.into_parts();
let bytes = match body let bytes = match body

View File

@ -43,7 +43,7 @@ async fn get_login(State(ctx): State<Context>, headers: HeaderMap, jar: CookieJa
.flatten() .flatten()
.is_some() .is_some()
{ {
Redirect::to("/_").into_response() Redirect::to("/").into_response()
} else { } else {
View::Login View::Login
.page(&headers) .page(&headers)
@ -87,7 +87,7 @@ async fn post_login(
.path("/") .path("/")
.max_age(Duration::days(365)), .max_age(Duration::days(365)),
), ),
Redirect::to("/_"), Redirect::to("/"),
) )
.into_response()), .into_response()),
Err(AuthErr::UnknownUser | AuthErr::InvalidPassword) => { Err(AuthErr::UnknownUser | AuthErr::InvalidPassword) => {
@ -129,7 +129,7 @@ pub async fn auth_web_middleware(
) -> Response { ) -> Response {
// SAFETY: this extractor's error type is Infallible // SAFETY: this extractor's error type is Infallible
let jar: CookieJar = req.extract_parts().await.unwrap(); let jar: CookieJar = req.extract_parts().await.unwrap();
let redirect = Redirect::to("/_/login"); let redirect = Redirect::to("/login");
match extract_session(ctx, &jar).await { match extract_session(ctx, &jar).await {
Ok(Some(session)) => { Ok(Some(session)) => {

View File

@ -1,5 +1,5 @@
<article> <article>
<form hx-post="/_/login" hx-target="#inner"> <form hx-post="/login" hx-target="#inner">
<label for="username">Username:</label> <label for="username">Username:</label>
<input type="text" id="username" name="username"> <input type="text" id="username" name="username">
<label for="password">Password:</label> <label for="password">Password:</label>