diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-15 14:03:54 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-15 14:03:54 -0500 |
commit | d897bfe58aa32d0d93bb695a19fb05d274a0961a (patch) | |
tree | 2fea1e75e8d47fb02b158cbd2850204394ae4fd1 | |
parent | 165208f5fda1fdea13f50cac538d981dc1119abb (diff) | |
download | teleterm-d897bfe58aa32d0d93bb695a19fb05d274a0961a.tar.gz teleterm-d897bfe58aa32d0d93bb695a19fb05d274a0961a.zip |
serve the teleterm-web content
-rw-r--r-- | Cargo.lock | 18 | ||||
-rw-r--r-- | static/index.html | 12 | ||||
-rw-r--r-- | teleterm/Cargo.toml | 1 | ||||
-rw-r--r-- | teleterm/src/web.rs | 37 |
4 files changed, 64 insertions, 4 deletions
@@ -982,6 +982,17 @@ dependencies = [ ] [[package]] +name = "lazy-static-include" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd80064440e1d2d057f602460cbf24313e8939e3755aa4ed888bae9a2f582201" +dependencies = [ + "lazy_static", + "starts-ends-with-caseless", + "syn 1.0.7", +] + +[[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1930,6 +1941,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] +name = "starts-ends-with-caseless" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "423e8765e5ec86a05cf18aa54cf7fcb53fbf460f5e586c99386e4ae2647ea5b1" + +[[package]] name = "string" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1999,6 +2016,7 @@ dependencies = [ "futures", "gotham", "hyper", + "lazy-static-include", "lazy_static", "log", "mio", diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..58a7c36 --- /dev/null +++ b/static/index.html @@ -0,0 +1,12 @@ +<!doctype html> +<html> + <head> + <script type="module"> + import init from "./teleterm_web.js"; + init(); + </script> + </head> + <body> + <h1>it's a page</h1> + </body> +</html> diff --git a/teleterm/Cargo.toml b/teleterm/Cargo.toml index f1e0ed0..0d28cb5 100644 --- a/teleterm/Cargo.toml +++ b/teleterm/Cargo.toml @@ -25,6 +25,7 @@ futures = "0.1.29" gotham = { git = "https://github.com/gotham-rs/gotham", rev = "d2395926b93710832f8d72b49c9bd3e77516e386" } hyper = "0.12" lazy_static = "1" +lazy-static-include = "2" log = { version = "0.4", features = ["release_max_level_info"] } mio = "0.6.19" native-tls = "0.2" diff --git a/teleterm/src/web.rs b/teleterm/src/web.rs index afc5128..5159233 100644 --- a/teleterm/src/web.rs +++ b/teleterm/src/web.rs @@ -3,17 +3,46 @@ mod ws; use futures::{Future as _, Sink as _, Stream as _}; use gotham::router::builder::{DefineSingleRoute as _, DrawRoutes as _}; use gotham::state::FromState as _; +use lazy_static::lazy_static; +use lazy_static_include::*; + +lazy_static_include::lazy_static_include_bytes!( + INDEX_HTML, + "../static/index.html" +); +lazy_static_include::lazy_static_include_bytes!( + TELETERM_WEB_JS, + "../target/wasm/teleterm_web.js" +); +lazy_static_include::lazy_static_include_bytes!( + TELETERM_WEB_WASM, + "../target/wasm/teleterm_web_bg.wasm" +); pub fn router() -> impl gotham::handler::NewHandler { gotham::router::builder::build_simple_router(|route| { - route.get("/").to(root); + route.get("/").to(serve_static("text/html", &INDEX_HTML)); + route + .get("/teleterm_web.js") + .to(serve_static("application/javascript", &TELETERM_WEB_JS)); + route + .get("/teleterm_web_bg.wasm") + .to(serve_static("application/wasm", &TELETERM_WEB_WASM)); route.get("/ws").to(handle_websocket_connection); }) } -fn root(state: gotham::state::State) -> (gotham::state::State, String) { - log::info!("request for /"); - (state, "hello world".to_string()) +fn serve_static( + content_type: &'static str, + s: &'static [u8], +) -> impl gotham::handler::Handler + Copy { + move |state| { + let response = hyper::Response::builder() + .header("Content-Type", content_type) + .body(hyper::Body::from(s)) + .unwrap(); + (state, response) + } } fn handle_websocket_connection( |