1
0
Fork 0
forked from alemi/upub

feat: root url redirects browsers to /web

This commit is contained in:
əlemi 2024-04-21 19:01:51 +02:00
parent abed664f0a
commit 48bba8af40
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -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<Context>) -> Result<JsonLD<serde_json::Value>, StatusCode> {
pub async fn view(
headers: HeaderMap,
State(ctx): State<Context>,
) -> crate::Result<Response> {
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<Context>) -> Result<JsonLD<serde_json::Value
.set_public_key_pem(&ctx.app().public_key)
))
.ld_context()
))
).into_response())
}