add route /game in backend
This commit is contained in:
@@ -9,6 +9,7 @@ use tower_http::services::ServeDir;
|
|||||||
async fn main() {
|
async fn main() {
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/", get(handler))
|
.route("/", get(handler))
|
||||||
|
.route("/game", get(game))
|
||||||
.nest_service("/web/assets", ServeDir::new("../web/assets"));
|
.nest_service("/web/assets", ServeDir::new("../web/assets"));
|
||||||
|
|
||||||
let addr = SocketAddr::from(([0, 0, 0, 0], 3500));
|
let addr = SocketAddr::from(([0, 0, 0, 0], 3500));
|
||||||
@@ -26,6 +27,13 @@ async fn handler() -> Html<String> {
|
|||||||
Html(html_content)
|
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> {
|
async fn read_html_from_file<P: AsRef<Path>>(path: P) -> io::Result<String> {
|
||||||
let mut file = File::open(path).await?;
|
let mut file = File::open(path).await?;
|
||||||
let mut contents = String::new();
|
let mut contents = String::new();
|
||||||
|
|||||||
@@ -14,11 +14,13 @@
|
|||||||
<div class="hero-content">
|
<div class="hero-content">
|
||||||
<h1>MirrorGame</h1>
|
<h1>MirrorGame</h1>
|
||||||
<img src="https://upload.wikimedia.org/wikipedia/commons/f/f3/Meow_cat_-_Mdebona.jpg" alt="MirrorGame">
|
<img src="https://upload.wikimedia.org/wikipedia/commons/f/f3/Meow_cat_-_Mdebona.jpg" alt="MirrorGame">
|
||||||
|
<a href="/game">
|
||||||
<button class="hero-play-button">
|
<button class="hero-play-button">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-play" viewBox="0 0 16 16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-play" viewBox="0 0 16 16">
|
||||||
<path d="M10.804 8 5 4.633v6.734zm.792-.696a.802.802 0 0 1 0 1.392l-6.363 3.692C4.713 12.69 4 12.345 4 11.692V4.308c0-.653.713-.998 1.233-.696z"/>
|
<path d="M10.804 8 5 4.633v6.734zm.792-.696a.802.802 0 0 1 0 1.392l-6.363 3.692C4.713 12.69 4 12.345 4 11.692V4.308c0-.653.713-.998 1.233-.696z"/>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<aside class="leftadsbanner">
|
<aside class="leftadsbanner">
|
||||||
|
|||||||
Reference in New Issue
Block a user