2023-05-30 00:17:23 +00:00
|
|
|
use std::net::SocketAddr;
|
2022-04-10 06:00:33 +00:00
|
|
|
|
2023-05-24 23:39:13 +00:00
|
|
|
use rand_core::{OsRng, RngCore};
|
2022-04-10 06:00:33 +00:00
|
|
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
2023-05-31 20:15:33 +00:00
|
|
|
use witch_watch::db;
|
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;
|
2023-05-29 00:55:16 +00:00
|
|
|
|
|
|
|
let secret = {
|
2023-05-29 21:25:50 +00:00
|
|
|
let mut bytes = [0u8; 64];
|
2023-05-29 00:55:16 +00:00
|
|
|
let mut rng = OsRng;
|
|
|
|
rng.fill_bytes(&mut bytes);
|
|
|
|
bytes
|
|
|
|
};
|
|
|
|
|
2023-05-31 20:15:33 +00:00
|
|
|
let app = witch_watch::app(pool, &secret).await;
|
2023-04-26 05:19:49 +00:00
|
|
|
|
2023-06-05 23:32:42 +00:00
|
|
|
let addr: SocketAddr = ([127, 0, 0, 1], 3000).into();
|
2023-05-31 20:15:33 +00:00
|
|
|
tracing::debug!("binding to {addr:?}");
|
|
|
|
|
2023-06-05 23:32:42 +00:00
|
|
|
axum::Server::bind(&addr)
|
2022-04-10 06:00:33 +00:00
|
|
|
.serve(app.into_make_service())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
}
|