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,
http::StatusCode,
middleware::Next,
response::{IntoResponse, Redirect, Response},
routing::get,
response::{IntoResponse, Response},
Router,
};
use http_body_util::BodyExt;
@ -26,11 +25,10 @@ pub struct Context {
pub fn app(ctx: Context) -> Router {
Router::new()
.merge(gpodder::router(ctx.clone()))
.merge(web::router(ctx.clone()))
.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(body_logger))
// .layer(axum::middleware::from_fn(body_logger))
.layer(TraceLayer::new_for_http())
.with_state(ctx)
}
@ -45,7 +43,7 @@ async fn header_logger(request: Request, next: Next) -> Response {
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 bytes = match body

View File

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

View File

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