| use axum::{ |
| extract::{Request, State}, |
| middleware::Next, |
| response::{IntoResponse, Response}, |
| http::StatusCode, |
| }; |
| use crate::proxy::server::AppState; |
|
|
| pub async fn service_status_middleware( |
| State(state): State<AppState>, |
| request: Request, |
| next: Next, |
| ) -> Response { |
| let path = request.uri().path(); |
| |
| |
| if path.starts_with("/api/") || path == "/auth/callback" || path == "/health" { |
| return next.run(request).await; |
| } |
|
|
| let running = { |
| let r = state.is_running.read().await; |
| *r |
| }; |
|
|
| if !running { |
| return ( |
| StatusCode::SERVICE_UNAVAILABLE, |
| "Proxy service is currently disabled".to_string(), |
| ) |
| .into_response(); |
| } |
|
|
| next.run(request).await |
| } |
|
|