add route /game in backend

This commit is contained in:
M1n-0
2026-03-31 14:31:40 +02:00
parent fa1ffc214c
commit 903a1de933
2 changed files with 15 additions and 5 deletions

View File

@@ -9,6 +9,7 @@ use tower_http::services::ServeDir;
async fn main() {
let app = Router::new()
.route("/", get(handler))
.route("/game", get(game))
.nest_service("/web/assets", ServeDir::new("../web/assets"));
let addr = SocketAddr::from(([0, 0, 0, 0], 3500));
@@ -26,6 +27,13 @@ async fn handler() -> Html<String> {
Html(html_content)
}
async fn game() -> Html<String> {
let html_content = read_html_from_file("../web/templates/view/game.html")
.await
.unwrap_or_else(|_| "<h1>Error loading HTML file</h1>".to_string());
Html(html_content)
}
async fn read_html_from_file<P: AsRef<Path>>(path: P) -> io::Result<String> {
let mut file = File::open(path).await?;
let mut contents = String::new();