feat: Move index route to it's own module
This commit is contained in:
parent
801aa7144f
commit
a689a064f4
|
@ -1,10 +1,15 @@
|
||||||
use axum::{response::Html, routing::get, Router};
|
use axum::{routing::get, Router};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
|
use stranger_site::routes::index::index;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// build our application with a route
|
// build our application with a route
|
||||||
let app = Router::new().route("/", get(handler));
|
let app = Router::new()
|
||||||
|
.route("/", get(index))
|
||||||
|
.route("/index", get(index))
|
||||||
|
.route("/index.html", get(index));
|
||||||
|
|
||||||
// run it
|
// run it
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
||||||
|
@ -14,7 +19,3 @@ async fn main() {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handler() -> Html<&'static str> {
|
|
||||||
Html("<h1>Hello, World!</h1>")
|
|
||||||
}
|
|
||||||
|
|
15
src/lib.rs
15
src/lib.rs
|
@ -1,14 +1 @@
|
||||||
pub fn add(left: usize, right: usize) -> usize {
|
pub mod routes;
|
||||||
left + right
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
let result = add(2, 2);
|
|
||||||
assert_eq!(result, 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
pub mod index;
|
|
@ -0,0 +1,6 @@
|
||||||
|
use axum::response::Html;
|
||||||
|
|
||||||
|
/// Render the front page
|
||||||
|
pub async fn index() -> Html<String> {
|
||||||
|
Html("<h1>Hello, World!</h1>".to_string())
|
||||||
|
}
|
Loading…
Reference in New Issue