diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/web.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/bin/web.rs b/src/bin/web.rs index 86effcf..4b63572 100644 --- a/src/bin/web.rs +++ b/src/bin/web.rs @@ -10,7 +10,28 @@ use axum::{ }; async fn root_get() -> Html<String> { - Html(fs::read_to_string("front/index.html").unwrap()) + let head = " + <head> + <meta charset=\"UTF-8\"> + <title>Hiccup</title> + <script src=\"/main.js\"></script> + </head> + "; + let body = " + <body> + <div id=\"main\"></div> + <script> + var app = Elm.Main.init({ + node: document.getElementById('main') + }); + </script> + </body> + "; + Html(format!("<!DOCTYPE html>{head}{body}")) +} + +async fn main_get() -> Html<String> { + Html(fs::read_to_string("front/main.js").unwrap()) } #[derive(Deserialize)] @@ -32,6 +53,7 @@ async fn main() { // build our application with a single route let app = Router::new() .route("/", get(root_get)) + .route("/main.js", get(main_get)) .route("/api/simulate", get(api_simulate_get)); // run our app with hyper, listening globally on port 3000 |