read the file for every request to allow for faster web development

This commit is contained in:
Rusty Striker 2025-06-15 18:36:19 +03:00
parent bdb0436c9f
commit 69d6ea2742
Signed by: RustyStriker
GPG key ID: 87E4D691632DFF15

View file

@ -29,6 +29,7 @@ async fn main() {
let game = open_tavern::GameServer::new(); let game = open_tavern::GameServer::new();
tokio::spawn(game.server_loop(mrecv, bsend)); tokio::spawn(game.server_loop(mrecv, bsend));
println!("Server is running at http://localhost:3001");
axum::serve(listener, app) axum::serve(listener, app)
.await .await
.expect("axum server crashed, yaaaaay (unless i crashed him that yay)"); .expect("axum server crashed, yaaaaay (unless i crashed him that yay)");
@ -167,26 +168,26 @@ async fn handle_socket(
println!("Done with so-cat"); println!("Done with so-cat");
} }
async fn root() -> axum::response::Html<&'static str> { async fn root() -> axum::response::Html<String> {
response::Html(include_str!("../assets/web/index.html")) response::Html(std::fs::read_to_string("./assets/web/index.html").expect("Failed finding index.html"))
} }
async fn socket() -> impl response::IntoResponse { async fn socket() -> impl response::IntoResponse {
( (
[(axum::http::header::CONTENT_TYPE, "text/javascript")], [(axum::http::header::CONTENT_TYPE, "text/javascript")],
include_str!("../assets/web/tavern.js"), std::fs::read_to_string("./assets/web/tavern.js").expect("Failed finding tavern.js"),
) )
} }
async fn app_js() -> impl response::IntoResponse { async fn app_js() -> impl response::IntoResponse {
( (
[(axum::http::header::CONTENT_TYPE, "text/javascript")], [(axum::http::header::CONTENT_TYPE, "text/javascript")],
include_str!("../assets/web/app.js"), std::fs::read_to_string("./assets/web/app.js").expect("Failed finding app.js"),
) )
} }
async fn style() -> impl response::IntoResponse { async fn style() -> impl response::IntoResponse {
( (
[(axum::http::header::CONTENT_TYPE, "text/css")], [(axum::http::header::CONTENT_TYPE, "text/css")],
include_str!("../assets/web/style.css"), std::fs::read_to_string("./assets/web/style.css").unwrap(),
) )
} }