aboutsummaryrefslogtreecommitdiff
path: root/src/bin/web.rs
diff options
context:
space:
mode:
authorGuillermo Ramos2025-02-21 17:33:00 +0100
committerGuillermo Ramos2025-02-21 17:47:46 +0100
commit484d62913300d6f3ce73522affc91ff6384d11d9 (patch)
tree4ab24d6ffa0b09a9ceba198d58cf5fa32248f5e6 /src/bin/web.rs
parente82162fbaf16703d9e9b589e7eb2ff8c62713838 (diff)
downloadhiccup-484d62913300d6f3ce73522affc91ff6384d11d9.tar.gz
Compile Elm to js instead of html
Diffstat (limited to 'src/bin/web.rs')
-rw-r--r--src/bin/web.rs24
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