From 48bba8af4029c9f9432bccb4fc10382d20f8c7f4 Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 21 Apr 2024 19:01:51 +0200 Subject: [PATCH] feat: root url redirects browsers to /web --- src/routes/activitypub/application.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/routes/activitypub/application.rs b/src/routes/activitypub/application.rs index d3e01ad8..57510cc1 100644 --- a/src/routes/activitypub/application.rs +++ b/src/routes/activitypub/application.rs @@ -1,12 +1,22 @@ use apb::{ActorMut, BaseMut, ObjectMut, PublicKeyMut}; -use axum::{extract::State, http::StatusCode}; +use axum::{extract::State, http::HeaderMap, response::{IntoResponse, Redirect, Response}}; use crate::{server::Context, url}; use super::{jsonld::LD, JsonLD}; -pub async fn view(State(ctx): State) -> Result, StatusCode> { +pub async fn view( + headers: HeaderMap, + State(ctx): State, +) -> crate::Result { + if let Some(accept) = headers.get("Accept") { + if let Ok(accept) = accept.to_str() { + if accept.contains("text/html") { + return Ok(Redirect::to("/web").into_response()); + } + } + } Ok(JsonLD( serde_json::Value::new_object() .set_id(Some(&url!(ctx, ""))) @@ -23,5 +33,5 @@ pub async fn view(State(ctx): State) -> Result