added more support for supabase-js
This commit is contained in:
@@ -2,12 +2,13 @@ mod middleware;
|
||||
mod state;
|
||||
|
||||
use axum::{
|
||||
extract::Request,
|
||||
extract::{Request, Query},
|
||||
middleware::{from_fn, from_fn_with_state, Next},
|
||||
response::Response,
|
||||
response::{Response, IntoResponse},
|
||||
routing::get,
|
||||
Router,
|
||||
};
|
||||
use axum::http::StatusCode;
|
||||
use axum_prometheus::PrometheusMetricLayer;
|
||||
use common::{init_pool, Config};
|
||||
use state::AppState;
|
||||
@@ -22,13 +23,36 @@ use tower_http::trace::TraceLayer;
|
||||
use moka::future::Cache;
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
async fn logs_proxy_handler(Query(params): Query<HashMap<String, String>>) -> impl IntoResponse {
|
||||
let client = reqwest::Client::new();
|
||||
// Use 'loki' as hostname since it's the service name in docker-compose
|
||||
let loki_url = "http://loki:3100/loki/api/v1/query_range";
|
||||
|
||||
let resp = client.get(loki_url)
|
||||
.query(¶ms)
|
||||
.send()
|
||||
.await;
|
||||
|
||||
match resp {
|
||||
Ok(r) => {
|
||||
let status = StatusCode::from_u16(r.status().as_u16()).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
|
||||
let body = r.bytes().await.unwrap_or_default();
|
||||
(status, body).into_response()
|
||||
},
|
||||
Err(e) => {
|
||||
tracing::error!("Loki proxy error: {}", e);
|
||||
(StatusCode::BAD_GATEWAY, e.to_string()).into_response()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn log_headers(req: Request, next: Next) -> Response {
|
||||
tracing::debug!("Request Headers: {:?}", req.headers());
|
||||
next.run(req).await
|
||||
}
|
||||
|
||||
async fn dashboard_handler() -> axum::response::Html<&'static str> {
|
||||
axum::response::Html(include_str!("../../web/index.html"))
|
||||
axum::response::Html(include_str!("../../web/admin.html"))
|
||||
}
|
||||
|
||||
async fn wait_for_db(db_url: &str) -> sqlx::PgPool {
|
||||
@@ -64,7 +88,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
.init();
|
||||
}
|
||||
|
||||
tracing::info!("Starting MadBase Gateway...");
|
||||
tracing::info!("Starting MadBase Gateway v4.1 (Admin UI)...");
|
||||
|
||||
// Initialize Database (Control Plane / Main DB)
|
||||
tracing::info!("Connecting to database at {}...", config.database_url);
|
||||
@@ -122,6 +146,16 @@ async fn main() -> anyhow::Result<()> {
|
||||
// Storage Init
|
||||
let storage_router = storage::init(pool.clone(), config.clone()).await;
|
||||
|
||||
// Functions Init
|
||||
let functions_runtime = Arc::new(functions::runtime::WasmRuntime::new().expect("Failed to initialize WASM runtime"));
|
||||
let deno_runtime = Arc::new(functions::deno_runtime::DenoRuntime::new());
|
||||
let functions_state = functions::FunctionsState {
|
||||
db: pool.clone(),
|
||||
config: config.clone(),
|
||||
runtime: functions_runtime,
|
||||
deno_runtime,
|
||||
};
|
||||
|
||||
// Auth Middleware State
|
||||
let auth_middleware_state = auth::AuthMiddlewareState {
|
||||
config: config.clone(),
|
||||
@@ -165,6 +199,13 @@ async fn main() -> anyhow::Result<()> {
|
||||
auth::auth_middleware,
|
||||
)),
|
||||
)
|
||||
.nest(
|
||||
"/functions/v1",
|
||||
functions::router(functions_state).layer(from_fn_with_state(
|
||||
auth_middleware_state.clone(),
|
||||
auth::auth_middleware,
|
||||
)),
|
||||
)
|
||||
.layer(from_fn_with_state(
|
||||
project_middleware_state.clone(),
|
||||
middleware::inject_tenant_pool,
|
||||
@@ -194,7 +235,8 @@ async fn main() -> anyhow::Result<()> {
|
||||
.nest("/", tenant_routes) // Apply project resolution to these
|
||||
.nest(
|
||||
"/platform/v1", // Admin/Control Plane API (No project resolution needed)
|
||||
control_plane::router(control_state),
|
||||
control_plane::router(control_state)
|
||||
.route("/logs", get(logs_proxy_handler)),
|
||||
)
|
||||
.layer(GovernorLayer {
|
||||
config: governor_conf,
|
||||
|
||||
Reference in New Issue
Block a user