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};
|
2023-05-12 19:08:18 +00:00
|
|
|
use witch_watch::{db, handlers};
|
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
|
2023-05-10 19:08:03 +00:00
|
|
|
use handlers::*;
|
2023-04-26 05:19:49 +00:00
|
|
|
let app = Router::new()
|
|
|
|
.route(
|
|
|
|
"/",
|
|
|
|
get(using_connection_pool_extractor).post(using_connection_extractor),
|
|
|
|
)
|
|
|
|
.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();
|
|
|
|
}
|