@@ -3,7 +3,7 @@ use std::{net::SocketAddr, sync::Arc, time::Duration};
3
3
use axum:: {
4
4
extract:: { Path , State } ,
5
5
http,
6
- routing:: post,
6
+ routing:: { get , post} ,
7
7
Router ,
8
8
} ;
9
9
use svix_bridge_types:: {
@@ -37,13 +37,34 @@ fn router() -> Router<InternalState> {
37
37
"/webhook/:integration_id/" ,
38
38
post ( route) . put ( route) . get ( route) . patch ( route) ,
39
39
)
40
+ . route ( "/health" , get ( health_handler) )
40
41
}
42
+ static START_TIME : once_cell:: sync:: Lazy < std:: time:: Instant > =
43
+ once_cell:: sync:: Lazy :: new ( std:: time:: Instant :: now) ;
41
44
45
+ fn get_uptime_seconds ( ) -> u64 {
46
+ START_TIME . elapsed ( ) . as_secs ( )
47
+ }
48
+ #[ derive( serde:: Serialize ) ]
49
+ struct HealthResponse {
50
+ pub status : & ' static str ,
51
+ pub version : & ' static str ,
52
+ pub uptime : u64 ,
53
+ }
54
+ async fn health_handler ( ) -> impl axum:: response:: IntoResponse {
55
+ let health_response = HealthResponse {
56
+ status : "OK" ,
57
+ version : env ! ( "CARGO_PKG_VERSION" ) ,
58
+ uptime : get_uptime_seconds ( ) ,
59
+ } ;
60
+ axum:: Json ( health_response)
61
+ }
42
62
pub async fn run (
43
63
listen_addr : SocketAddr ,
44
64
routes : Vec < WebhookReceiverConfig > ,
45
65
transformer_tx : TransformerTx ,
46
66
) -> std:: io:: Result < ( ) > {
67
+ once_cell:: sync:: Lazy :: force ( & START_TIME ) ;
47
68
let state = InternalState :: from_receiver_configs ( routes, transformer_tx)
48
69
. await
49
70
. map_err ( std:: io:: Error :: other) ?;
0 commit comments