Skip to content

Commit

Permalink
fix: Make sure to serve the TD from its inherent base
Browse files Browse the repository at this point in the history
It unbreaks consuming a TD served from `.well-known/wot` when
the Thing::base is not set.

(See https://www.rfc-editor.org/rfc/rfc3986#section-5.1.3)
  • Loading branch information
lu-zero committed Sep 7, 2023
1 parent 3a78ccd commit 2f63bdd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/servient/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
hlist::*,
servient::Servient,
};
use axum::{handler::Handler, routing::MethodRouter, Router};
use axum::{handler::Handler, response::Redirect, routing::MethodRouter, Router};
use tower_http::cors::*;

use datta::{Operator, UriTemplate};
Expand Down Expand Up @@ -189,9 +189,14 @@ where
// TODO: Figure out how to share the thing description and if we want to.
let json = serde_json::to_value(&thing)?;

// We serve The thing from the root
router = router.route("/", axum::routing::get(move || async { axum::Json(json) }));

// We redirect this path to / to support relative Forms with empty base
// See: https://www.rfc-editor.org/rfc/rfc3986#section-5.1.3
router = router.route(
"/.well-known/wot",
axum::routing::get(move || async { axum::Json(json) }),
axum::routing::get(move || async { Redirect::to("/") }),
);

if thing.other.field_ref().permissive_cors {
Expand Down

0 comments on commit 2f63bdd

Please sign in to comment.