//! `web_assets` — the browser client's static files, embedded at compile time //! so the server ships as a single binary with no runtime filesystem //! dependency. The actual HTML/CSS/JS live under `assets/`. pub const INDEX_HTML: &str = include_str!("../assets/index.html"); pub const STYLE_CSS: &str = include_str!("../assets/style.css"); pub const APP_JS: &str = include_str!("../assets/app.js"); /// A served asset: its bytes and MIME type. pub struct Asset { pub body: &'static str, pub content_type: &'static str, } /// Resolve a request path to a static asset. `/` maps to the client shell. pub fn resolve(path: &str) -> Option { match path { "/" | "/index.html" => Some(Asset { body: INDEX_HTML, content_type: "text/html; charset=utf-8" }), "/style.css" => Some(Asset { body: STYLE_CSS, content_type: "text/css; charset=utf-8" }), "/app.js" => Some(Asset { body: APP_JS, content_type: "application/javascript; charset=utf-8" }), _ => None, } } #[cfg(test)] mod tests { use super::*; #[test] fn shell_and_assets_resolve() { assert!(resolve("/").is_some()); assert!(resolve("/app.js").is_some()); assert!(resolve("/style.css").is_some()); assert!(resolve("/nope").is_none()); } #[test] fn client_only_sends_intent() { // Guard against the client ever embedding a second simulation: the // browser code must not reference the reference engine internals. assert!(!APP_JS.contains("EngineConfig")); assert!(APP_JS.contains("only ever sends INTENT")); } }