forked from alemi/upub
feat: root url redirects browsers to /web
This commit is contained in:
parent
abed664f0a
commit
48bba8af40
1 changed files with 13 additions and 3 deletions
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue