From 5fc272054c00c590bf3ef0d8220cf55343843be6 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Fri, 5 Jul 2024 20:00:52 -0700 Subject: [PATCH] Put all URLs under /api/ --- server/src/bin/server.rs | 2 +- server/src/graphql.rs | 2 +- shared/src/lib.rs | 21 +++++++++++++++++++++ web/Trunk.toml | 15 +-------------- web/src/graphql.rs | 2 +- web/src/view/mod.rs | 2 +- 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/server/src/bin/server.rs b/server/src/bin/server.rs index 7bc5308..0de3fcc 100644 --- a/server/src/bin/server.rs +++ b/server/src/bin/server.rs @@ -231,7 +231,7 @@ async fn main() -> Result<(), Box> { let _ = rocket::build() .mount( - "/", + shared::urls::MOUNT_POINT, routes![ original, refresh, diff --git a/server/src/graphql.rs b/server/src/graphql.rs index 59e2796..993b334 100644 --- a/server/src/graphql.rs +++ b/server/src/graphql.rs @@ -337,7 +337,7 @@ impl QueryRoot { .headers .get_first_value("date") .and_then(|d| mailparse::dateparse(&d).ok()); - let cid_prefix = format!("/cid/{id}/"); + let cid_prefix = shared::urls::cid_prefix(None, &id); let body = match extract_body(&m, &id)? { Body::PlainText(PlainText { text, content_tree }) => { let text = if text.len() > MAX_RAW_MESSAGE_SIZE { diff --git a/shared/src/lib.rs b/shared/src/lib.rs index 866479a..e5f5cf3 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -12,3 +12,24 @@ pub struct SearchResult { #[derive(Serialize, Deserialize, Debug)] pub struct Message {} + +pub mod urls { + pub const MOUNT_POINT: &'static str = "/api"; + pub fn cid_prefix(host: Option<&str>, cid: &str) -> String { + if let Some(host) = host { + format!("//{host}/api/cid/{cid}/") + } else { + format!("/api/cid/{cid}/") + } + } + pub fn download_attachment(host: Option<&str>, id: &str, idx: &str, filename: &str) -> String { + if let Some(host) = host { + format!( + "//{host}/api/download/attachment/{}/{}/{}", + id, idx, filename + ) + } else { + format!("/api/download/attachment/{}/{}/{}", id, idx, filename) + } + } +} diff --git a/web/Trunk.toml b/web/Trunk.toml index e5e1e26..47b5187 100644 --- a/web/Trunk.toml +++ b/web/Trunk.toml @@ -7,20 +7,7 @@ address = "0.0.0.0" port = 6758 [[proxy]] -backend = "http://localhost:9345/" -rewrite= "/api/" -[[proxy]] -backend="http://localhost:9345/cid" -[[proxy]] -backend="http://localhost:9345/original" -[[proxy]] -backend="http://localhost:9345/graphiql" -[[proxy]] -backend="http://localhost:9345/graphql" -[[proxy]] -backend="http://localhost:9345/download" -[[proxy]] -backend="http://localhost:9345/view" +backend = "http://localhost:9345/api/" [[hooks]] stage = "pre_build" diff --git a/web/src/graphql.rs b/web/src/graphql.rs index 3f0ae16..7f3c924 100644 --- a/web/src/graphql.rs +++ b/web/src/graphql.rs @@ -51,7 +51,7 @@ where { use web_sys::RequestMode; - Request::post("/graphql/") + Request::post("/api/graphql/") .mode(RequestMode::Cors) .json(&body)? .send() diff --git a/web/src/view/mod.rs b/web/src/view/mod.rs index a9a598a..5dbc89d 100644 --- a/web/src/view/mod.rs +++ b/web/src/view/mod.rs @@ -732,7 +732,7 @@ fn message_render(msg: &ShowThreadQueryThreadMessages, open: bool) -> Node let default = "UNKNOWN_FILE".to_string(); let filename = a.filename.as_ref().unwrap_or(&default); let host = seed::window().location().host().expect("couldn't get host"); - let url = format!("//{host}/download/attachment/{}/{}/{}", a.id,a.idx, filename); + let url = shared::urls::download_attachment(Some(&host), &a.id, &a.idx, filename); let mut fmtr = Formatter::new(); fmtr.with_separator(" "); fmtr.with_scales(Scales::Binary());