Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
A page's <img> (and url(), @font-face) of its own /host/* loads from its host in raea's window
shinyobjectz373b47b964d1
diff --git a/systems/page-net/src/host.rs b/systems/page-net/src/host.rsindex 4e0928ed..d9186dd0 100644--- a/systems/page-net/src/host.rs+++ b/systems/page-net/src/host.rs@@ -1,6 +1,7 @@//! raea's window on the feed (docs/app.feature AP5/AP6): with RAEA_PAGE_HOST (the feed's Node host, http://127.0.0.1:PORT),//! the page's /host/* is that host's, and so is a /media/* that isn't on disk (a render the host made after the page-//! loaded); everything else is page_fetch's.+//! loaded); everything else is page_fetch's. What the page loads by itself (an <img>, a stylesheet's url(), a font)+//! from its /host/* is the host's too (`load`).use base64::Engine as _;@@ -23,6 +24,23 @@ pub fn fetch(args: &serde_json::Value) -> Option<serde_json::Value> {Some(r)}+/// A load the page makes by itself (an <img>'s src, a stylesheet's url(), a @font-face) of its own /host/*: the bytes+/// the host answers, as its fetch has them. None for any other URL, without a host, or when the host doesn't answer+/// 2xx. Before, FileNet looked for /host/* among the page's files, so an <img> of one drew nothing in raea's window+/// (the feed's pictures attached to a note, a library's posters on Publish).+pub fn load(u: &url::Url) -> Option<Vec<u8>> {+ let own = u.scheme() == "http" && u.host_str() == Some("localhost") && u.port().is_none();+ if !own || !u.path().starts_with("/host/") {+ return None;+ }+ let r = to_host(&serde_json::json!({ "url": u.as_str(), "method": "GET" }), u)?;+ let status = r["status"].as_u64()?;+ if !(200..300).contains(&status) {+ return None;+ }+ base64::engine::general_purpose::STANDARD.decode(r["body"].as_str()?).ok()+}+/// The request sent on to RAEA_PAGE_HOST (method, headers and body as the page gave them), its answer as `fetch` gives/// one; None when there's no host. A host that doesn't answer is a 502, so the page sees the failure, not a hang.fn to_host(args: &serde_json::Value, u: &url::Url) -> Option<serde_json::Value> {diff --git a/systems/page-net/src/lib.rs b/systems/page-net/src/lib.rsindex dede0c86..2548d358 100644--- a/systems/page-net/src/lib.rs+++ b/systems/page-net/src/lib.rs@@ -6,7 +6,7 @@use blitz_traits::net::{Bytes, NetHandler, NetProvider, Request};mod host;-pub use host::fetch;+pub use host::{fetch, load as host_load};/// Files and data URLs; a path that isn't on disk is looked for under each of `roots` in turn (a server's root: WPT's/// `/css/...`).@@ -68,6 +68,8 @@ impl NetProvider for FileNet {})}),"data" => raea_io_net::data_url(url.as_str()).map(|(_, b)| b),+ // the page's own /host/*: its host's (RAEA_PAGE_HOST), as the page's fetch of it is (host.rs)+ "http" if url.host_str() == Some("localhost") && url.port().is_none() && url.path().starts_with("/host/") => host::load(&url),// the page's own origin (http://localhost/, as page_fetch has it): the file under the roots, confined, so an// @font-face, image or stylesheet the app names by its URL loads as in Chrome (Excalidraw's fonts did not)"http" if url.host_str() == Some("localhost") && url.port().is_none() && !self.roots.is_empty() => {diff --git a/systems/page-net/tests/page_host.rs b/systems/page-net/tests/page_host.rsindex bb732821..8f25ef77 100644--- a/systems/page-net/tests/page_host.rs+++ b/systems/page-net/tests/page_host.rs@@ -5,7 +5,7 @@use std::io::{Read, Write};use std::net::TcpListener;-use raea_sys_page_net::fetch as page_fetch;+use raea_sys_page_net::{fetch as page_fetch, host_load};use serde_json::json;/// A host that answers each request with its own request line as the body.@@ -50,10 +50,17 @@ fn the_page_reaches_its_host() {assert_eq!(body(&fetch("http://localhost/media/feed/new.mp4", "GET")), "GET /media/feed/new.mp4 HTTP/1.1");assert_eq!(body(&fetch("http://localhost/media/on-disk.wav", "GET")), "RIFF");+ // what the page loads by itself (an <img>'s src) of its /host/* is the host's too, with its query; nothing else is+ let load = |u: &str| host_load(&url::Url::parse(u).unwrap()).map(|b| String::from_utf8(b).unwrap());+ assert_eq!(load("http://localhost/host/attachment?project=p&name=ref.png").as_deref(), Some("GET /host/attachment?project=p&name=ref.png HTTP/1.1"));+ assert_eq!(load("http://localhost/media/on-disk.wav"), None);+ assert_eq!(load("https://example.com/host/x"), None);+// a host that's gonelet gone = TcpListener::bind("127.0.0.1:0").unwrap().local_addr().unwrap();unsafe { std::env::set_var("RAEA_PAGE_HOST", format!("http://{gone}")) };assert_eq!(fetch("http://localhost/host/acp/act", "POST")["status"], 502);+ assert_eq!(load("http://localhost/host/attachment?name=ref.png"), None);std::fs::remove_dir_all(&root).unwrap();}