what2watch/src/main.rs

40 lines
1.2 KiB
Rust
Raw Normal View History

2023-05-10 19:08:03 +00:00
use std::net::SocketAddr;
2022-04-10 06:00:33 +00:00
2023-05-10 19:08:03 +00:00
use axum::{routing::get, Router};
2022-04-10 06:00:33 +00:00
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
use witch_watch::{
db,
2023-05-22 23:57:08 +00:00
generic_handlers::{handle_slash, handle_slash_redir},
users::{get_create_user, handle_signup_success, post_create_user},
};
2023-05-10 19:08:03 +00:00
2022-04-10 06:00:33 +00:00
#[tokio::main]
async fn main() {
tracing_subscriber::registry()
2023-04-26 05:19:49 +00:00
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
2023-05-10 19:08:03 +00:00
.unwrap_or_else(|_| "witch_watch=debug,axum::routing=info".into()),
2023-04-26 05:19:49 +00:00
)
2022-04-10 06:00:33 +00:00
.with(tracing_subscriber::fmt::layer())
.init();
2023-05-10 19:08:03 +00:00
let pool = db::get_pool().await;
2022-04-10 06:00:33 +00:00
2023-04-26 05:19:49 +00:00
// build our application with some routes
let app = Router::new()
2023-05-22 23:57:08 +00:00
.route("/", get(handle_slash).post(handle_slash))
.route("/signup", get(get_create_user).post(post_create_user))
2023-05-20 00:17:24 +00:00
.route(
"/signup_success/:id",
get(handle_signup_success).post(handle_signup_success),
2023-05-20 00:17:24 +00:00
)
2023-05-22 23:57:08 +00:00
.fallback(handle_slash_redir)
2023-04-26 05:19:49 +00:00
.with_state(pool);
2023-05-10 19:08:03 +00:00
tracing::debug!("binding to 0.0.0.0:3000");
2023-04-26 05:19:49 +00:00
axum::Server::bind(&SocketAddr::from(([0, 0, 0, 0], 3000)))
2022-04-10 06:00:33 +00:00
.serve(app.into_make_service())
.await
.unwrap();
}