aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--front/.gitignore1
-rw-r--r--front/src/Main.elm2
-rw-r--r--src/bin/web.rs24
4 files changed, 26 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 1c39913..ad7cba4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
build:
- cd front && elm make src/Main.elm
+ cd front && elm make src/Main.elm --output main.js
cargo build -r
serve: build
diff --git a/front/.gitignore b/front/.gitignore
index e453cba..9e98d05 100644
--- a/front/.gitignore
+++ b/front/.gitignore
@@ -1,2 +1,3 @@
elm-stuff
index.html
+main.js
diff --git a/front/src/Main.elm b/front/src/Main.elm
index 9139158..7f6522b 100644
--- a/front/src/Main.elm
+++ b/front/src/Main.elm
@@ -1,4 +1,4 @@
-module Main exposing (..)
+module Main exposing (main)
import Round
import Browser
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