From 0876ae137788658f42b20906103a29ce767e1ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20H=C3=B6ffner?= Date: Fri, 16 Jun 2023 10:52:43 +0200 Subject: [PATCH] Fix base path. Add missing trailing slash on root resource. Release 0.2.1. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4702671..3bdf6c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1122,7 +1122,7 @@ checksum = "cbc95d56eb1865f69288945759cc0879d60ee68168dce676730275804ad2b276" [[package]] name = "rickview" -version = "0.2.0" +version = "0.2.1" dependencies = [ "actix-web", "bytesize", diff --git a/Cargo.toml b/Cargo.toml index bf0966d..6bfa781 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rickview" -version = "0.2.0" +version = "0.2.1" edition = "2021" license = "MIT" keywords = ["rdf", "semantic-web", "linked-data"] diff --git a/src/main.rs b/src/main.rs index 6e69b6c..e7f5f99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ use const_fnv1a_hash::fnv1a_hash_str_32; use log::{debug, error, info, trace, warn}; use serde::Deserialize; use serde_json::Value; -use sophia::iri::{Iri, IriRef}; +use sophia::iri::IriRef; use std::error::Error; use std::sync::atomic::{AtomicU32, Ordering}; use std::time::{Instant, SystemTime, UNIX_EPOCH}; @@ -146,7 +146,7 @@ async fn res_html(r: HttpRequest, suffix: web::Path, params: web::Query< res_html_sync(&r, &suffix, ¶ms) } -#[get("")] +#[get("/")] async fn base(r: HttpRequest, params: web::Query) -> impl Responder { res_html_sync(&r, "", ¶ms) } fn res_html_sync(r: &HttpRequest, suffix: &str, params: &web::Query) -> impl Responder { @@ -167,11 +167,11 @@ fn res_html_sync(r: &HttpRequest, suffix: &str, params: &web::Query) -> let output = params.output.as_deref(); let t = Instant::now(); let prefixed = config().prefix.to_string() + ":" + suffix; - let iri = if suffix.is_empty() { - Iri::new_unchecked(config().namespace.as_str().strip_suffix('/').expect("empty namespace").to_owned()) - } else { - config().namespace.resolve(IriRef::new_unchecked(suffix)) - }; + /*let iri = if suffix.is_empty() { + Iri::new_unchecked(config().namespace.as_str().to_owned()) + } else {*/ + let iri = config().namespace.resolve(IriRef::new_unchecked(suffix)); + //}; let mut res = rdf::resource(iri.as_ref()); // no triples found if res.directs.is_empty() && res.inverses.is_empty() { @@ -262,8 +262,8 @@ async fn about_page() -> impl Responder { async fn head() -> HttpResponse { HttpResponse::MethodNotAllowed().body("RickView does not support HEAD requests.") } // redirect /base to correct index page /base/ -//#[get("")] -//async fn redirect() -> impl Responder { HttpResponse::TemporaryRedirect().append_header(("location", config().base.clone() + "/")).finish() } +#[get("")] +async fn redirect() -> impl Responder { HttpResponse::TemporaryRedirect().append_header(("location", config().base.clone() + "/")).finish() } #[actix_web::main] async fn main() -> std::io::Result<()> { @@ -280,7 +280,7 @@ async fn main() -> std::io::Result<()> { .service(roboto300) .service(favicon) .service(head) - .service(scope(&config().base).service(about_page).service(base).service(res_html)) + .service(scope(&config().base).service(about_page).service(base).service(res_html).service(redirect)) }) .bind(("0.0.0.0", config().port))? .run()