add route /game in backend
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user