chore: Add htmx on an index.html root page
This commit is contained in:
parent
12973bc840
commit
1f1eea31a0
27
src/main.rs
27
src/main.rs
@ -4,21 +4,30 @@ use axum::{
|
||||
};
|
||||
use askama_axum::Template;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let app = Router::new()
|
||||
.route("/", get(index))
|
||||
.route("/hello", get(hello_world));
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "index.html")]
|
||||
struct IndexTemplate {}
|
||||
|
||||
async fn index() -> IndexTemplate {
|
||||
IndexTemplate {}
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "hello.html")]
|
||||
struct HelloTemplate<'a> {
|
||||
name: &'a str,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let app = Router::new()
|
||||
.route("/", get(hello_world));
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}
|
||||
|
||||
async fn hello_world() -> HelloTemplate<'static> {
|
||||
HelloTemplate { name: "world" }
|
||||
}
|
||||
|
12
templates/index.html
Normal file
12
templates/index.html
Normal file
@ -0,0 +1,12 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Krys4lide</title>
|
||||
<script src="https://unpkg.com/htmx.org@2.0.0/dist/htmx.js" integrity="sha384-Xh+GLLi0SMFPwtHQjT72aPG19QvKB8grnyRbYBNIdHWc2NkCrz65jlU7YrzO6qRp" crossorigin="anonymous"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Krys4lide</h1>
|
||||
<button hx-get="/hello" hx-target="#hello">Hello!</button>
|
||||
<div id="hello"></div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user