From 177ee55e7d84d1de5189736d4f6a5f0627a57f92 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Tue, 3 Oct 2023 22:33:25 -0400 Subject: [PATCH] rename apps_home to homepage --- build.rs | 2 +- .../Cargo-component.lock | 0 modules/{apps_home => homepage}/Cargo.lock | 24 +++++++++---------- modules/{apps_home => homepage}/Cargo.toml | 2 +- modules/{apps_home => homepage}/src/home.html | 6 ++--- modules/{apps_home => homepage}/src/lib.rs | 24 +++++++++---------- .../src/process_lib.rs | 0 modules/http_bindings/src/lib.rs | 2 +- 8 files changed, 30 insertions(+), 30 deletions(-) rename modules/{apps_home => homepage}/Cargo-component.lock (100%) rename modules/{apps_home => homepage}/Cargo.lock (99%) rename modules/{apps_home => homepage}/Cargo.toml (97%) rename modules/{apps_home => homepage}/src/home.html (98%) rename modules/{apps_home => homepage}/src/lib.rs (88%) rename modules/{apps_home => homepage}/src/process_lib.rs (100%) diff --git a/build.rs b/build.rs index c9b48390..9f0bc934 100644 --- a/build.rs +++ b/build.rs @@ -32,7 +32,7 @@ fn main() { // Build wasm32-wasi apps. const WASI_APPS: [&str; 8] = [ - "apps_home", + "homepage", "chess", "http_bindings", "http_proxy", diff --git a/modules/apps_home/Cargo-component.lock b/modules/homepage/Cargo-component.lock similarity index 100% rename from modules/apps_home/Cargo-component.lock rename to modules/homepage/Cargo-component.lock diff --git a/modules/apps_home/Cargo.lock b/modules/homepage/Cargo.lock similarity index 99% rename from modules/apps_home/Cargo.lock rename to modules/homepage/Cargo.lock index c2062130..8dea4952 100644 --- a/modules/apps_home/Cargo.lock +++ b/modules/homepage/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" -[[package]] -name = "apps_home" -version = "0.1.0" -dependencies = [ - "anyhow", - "bincode", - "cargo-component-bindings", - "serde", - "serde_json", - "wit-bindgen 0.9.0", -] - [[package]] name = "bincode" version = "1.3.3" @@ -95,6 +83,18 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "homepage" +version = "0.1.0" +dependencies = [ + "anyhow", + "bincode", + "cargo-component-bindings", + "serde", + "serde_json", + "wit-bindgen 0.9.0", +] + [[package]] name = "id-arena" version = "2.2.1" diff --git a/modules/apps_home/Cargo.toml b/modules/homepage/Cargo.toml similarity index 97% rename from modules/apps_home/Cargo.toml rename to modules/homepage/Cargo.toml index cc211187..293c8b30 100644 --- a/modules/apps_home/Cargo.toml +++ b/modules/homepage/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "apps_home" +name = "homepage" version = "0.1.0" edition = "2021" diff --git a/modules/apps_home/src/home.html b/modules/homepage/src/home.html similarity index 98% rename from modules/apps_home/src/home.html rename to modules/homepage/src/home.html index fd1b72a1..9b50fc16 100644 --- a/modules/apps_home/src/home.html +++ b/modules/homepage/src/home.html @@ -228,7 +228,7 @@ // webSocket.send(JSON.stringify({ // Register: { // auth_token: getCookie(`uqbar-ws-auth_${window.our}`), - // channel_id: "apps_home" // Can be unique to this connection, app, or omitted entirely + // channel_id: "homepage" // Can be unique to this connection, app, or omitted entirely // } // })) @@ -238,9 +238,9 @@ // auth_token: getCookie(`uqbar-ws-auth_${window.our}`), // target: { // node: window.our, - // process: 'apps_home' + // process: 'homepage' // }, - // channel_id: 'apps_home', + // channel_id: 'homepage', // json: { // action: 'ping' // // You could add a unique ID here so that the server can respond to only this ID diff --git a/modules/apps_home/src/lib.rs b/modules/homepage/src/lib.rs similarity index 88% rename from modules/apps_home/src/lib.rs rename to modules/homepage/src/lib.rs index 2fecdfc4..aaf8b4cf 100644 --- a/modules/apps_home/src/lib.rs +++ b/modules/homepage/src/lib.rs @@ -8,7 +8,7 @@ mod process_lib; struct Component; -const APPS_HOME_PAGE: &str = include_str!("home.html"); +const HOME_PAGE: &str = include_str!("home.html"); fn generate_http_binding(add: Address, path: &str, authenticated: bool) -> (Address, Request, Option, Option) { ( @@ -19,7 +19,7 @@ fn generate_http_binding(add: Address, path: &str, authenticated: bool) -> (Addr ipc: Some(serde_json::json!({ "action": "bind-app", "path": path, - "app": "apps_home", + "app": "homepage", "authenticated": authenticated }).to_string()), metadata: None, @@ -31,7 +31,7 @@ fn generate_http_binding(add: Address, path: &str, authenticated: bool) -> (Addr impl Guest for Component { fn init(our: Address) { - print_to_terminal(1, "apps_home: start"); + print_to_terminal(1, "homepage: start"); let bindings_address = Address { node: our.node.clone(), @@ -46,28 +46,28 @@ impl Guest for Component { loop { let Ok((_source, message)) = receive() else { - print_to_terminal(0, "apps_home: got network error"); + print_to_terminal(0, "homepage: got network error"); continue; }; let Message::Request(request) = message else { - print_to_terminal(0, &format!("apps_home: got unexpected message: {:?}", message)); + print_to_terminal(0, &format!("homepage: got unexpected message: {:?}", message)); continue; }; if let Some(json) = request.ipc { - print_to_terminal(1, format!("apps_home: JSON {}", json).as_str()); + print_to_terminal(1, format!("homepage: JSON {}", json).as_str()); let message_json: serde_json::Value = match serde_json::from_str(&json) { Ok(v) => v, Err(_) => { - print_to_terminal(1, "apps_home: failed to parse ipc JSON, skipping"); + print_to_terminal(1, "homepage: failed to parse ipc JSON, skipping"); continue; }, }; - print_to_terminal(1, "apps_home: parsed ipc JSON"); + print_to_terminal(1, "homepage: parsed ipc JSON"); if message_json["path"] == "/" && message_json["method"] == "GET" { - print_to_terminal(1, "apps_home: sending response"); + print_to_terminal(1, "homepage: sending response"); send_response( &Response { @@ -82,7 +82,7 @@ impl Guest for Component { }, Some(&Payload { mime: Some("text/html".to_string()), - bytes: APPS_HOME_PAGE.replace("${our}", &our.node).to_string().as_bytes().to_vec(), + bytes: HOME_PAGE.replace("${our}", &our.node).to_string().as_bytes().to_vec(), }), ); } else if message_json["path"].is_string() { @@ -136,7 +136,7 @@ impl Guest for Component { expects_response: None, ipc: Some(serde_json::json!({ "EncryptAndForwardAction": { - "channel_id": "apps_home", + "channel_id": "homepage", "forward_to": { "node": our.node.clone(), "process": { @@ -147,7 +147,7 @@ impl Guest for Component { "WebSocketPush": { "target": { "node": our.node.clone(), - "id": "apps_home", // If the message passed in an ID then we could send to just that ID + "id": "homepage", // If the message passed in an ID then we could send to just that ID } } })), diff --git a/modules/apps_home/src/process_lib.rs b/modules/homepage/src/process_lib.rs similarity index 100% rename from modules/apps_home/src/process_lib.rs rename to modules/homepage/src/process_lib.rs diff --git a/modules/http_bindings/src/lib.rs b/modules/http_bindings/src/lib.rs index e1725079..17fc47fe 100644 --- a/modules/http_bindings/src/lib.rs +++ b/modules/http_bindings/src/lib.rs @@ -193,7 +193,7 @@ impl Guest for Component { .trim_start_matches('/') .split("/") .collect::>(); - if app != "apps_home" + if app != "homepage" && (path_segments.is_empty() || path_segments[0] != app.clone().replace("_", "-")) {