2024-07-14 15:19:41 -04:00
|
|
|
use axum::http::StatusCode;
|
2024-07-14 15:14:52 -04:00
|
|
|
use axum::routing::get;
|
2024-07-14 16:13:06 -04:00
|
|
|
use axum::routing::post;
|
2024-07-14 15:19:41 -04:00
|
|
|
use axum::Json;
|
2024-07-14 15:14:52 -04:00
|
|
|
use axum::Router;
|
2024-07-14 15:19:41 -04:00
|
|
|
use serde::Serialize;
|
2024-07-14 15:50:13 -04:00
|
|
|
use tower_http::trace::TraceLayer;
|
2024-07-14 15:34:14 -04:00
|
|
|
use tracing_subscriber::layer::SubscriberExt;
|
|
|
|
use tracing_subscriber::util::SubscriberInitExt;
|
2024-07-14 15:14:52 -04:00
|
|
|
|
2024-07-14 16:13:06 -04:00
|
|
|
use self::webhook::hook;
|
|
|
|
|
|
|
|
mod webhook;
|
|
|
|
|
2024-07-14 15:14:52 -04:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2024-07-14 15:34:14 -04:00
|
|
|
tracing_subscriber::registry()
|
|
|
|
.with(
|
|
|
|
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
|
|
|
|
"webhook_bridge=info,tower_http=debug,axum::rejection=trace".into()
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
.with(tracing_subscriber::fmt::layer())
|
|
|
|
.init();
|
2024-07-14 15:50:13 -04:00
|
|
|
let app = Router::new()
|
|
|
|
.route("/health", get(health))
|
2024-07-14 16:13:06 -04:00
|
|
|
.route("/hook", post(hook))
|
2024-07-14 15:50:13 -04:00
|
|
|
.layer(TraceLayer::new_for_http());
|
2024-07-14 15:14:52 -04:00
|
|
|
|
|
|
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
|
2024-07-14 15:34:14 -04:00
|
|
|
tracing::info!("listening on {}", listener.local_addr().unwrap());
|
2024-07-14 15:14:52 -04:00
|
|
|
axum::serve(listener, app).await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2024-07-14 15:19:41 -04:00
|
|
|
async fn health() -> (StatusCode, Json<HealthResponse>) {
|
|
|
|
(StatusCode::OK, Json(HealthResponse { ok: true }))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
struct HealthResponse {
|
|
|
|
ok: bool,
|
2024-07-14 14:52:45 -04:00
|
|
|
}
|