diff options
author | Tyler Murphy <tylermurphy534@gmail.com> | 2023-01-26 17:29:16 -0500 |
---|---|---|
committer | Tyler Murphy <tylermurphy534@gmail.com> | 2023-01-26 17:29:16 -0500 |
commit | 88209d88236c3d865a9f5174a0dced31920859bf (patch) | |
tree | 89a9985927393005cf632950b585a6a227b1c679 /src/main.rs | |
download | xssbook-88209d88236c3d865a9f5174a0dced31920859bf.tar.gz xssbook-88209d88236c3d865a9f5174a0dced31920859bf.tar.bz2 xssbook-88209d88236c3d865a9f5174a0dced31920859bf.zip |
i did things
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..9ad772d --- /dev/null +++ b/src/main.rs @@ -0,0 +1,48 @@ +use std::net::SocketAddr; +use axum::{Router, response::Response, http::Request, middleware::{Next, self}}; +use tower_cookies::CookieManagerLayer; +use types::response::ResponseCode; + +use crate::api::{pages, auth, users, posts}; + +mod api; +mod database; +mod types; + +async fn serve<B>(req: Request<B>, next: Next<B>) -> Response { + let Ok(file) = ResponseCode::Success.file(&req.uri().to_string()).await else { + return next.run(req).await + }; + file +} + +async fn not_found() -> Response { + match ResponseCode::NotFound.file("/404.html").await { + Ok(file) => file, + Err(err) => err + } +} + +#[tokio::main] +async fn main() { + + database::init().unwrap(); + + let app = Router::new() + .fallback(not_found) + .layer(middleware::from_fn(serve)) + .nest("/", pages::router()) + .nest("/api/auth", auth::router()) + .nest("/api/users", users::router()) + .nest("/api/posts", posts::router()) + .layer(CookieManagerLayer::new()); + + let addr = SocketAddr::from(([127, 0, 0, 1], 8080)); + println!("Listening on {}", addr); + + axum::Server::bind(&addr) + .serve(app.into_make_service()) + .await + .unwrap(); + +} |