what2watch/src/main.rs

34 lines
1000 B
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,
users::{get_create_user, get_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()
.route("/signup", get(get_create_user).post(post_create_user))
.route("/signup_success", get(get_signup_success))
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();
}