feat: implement admin api v1
This commit is contained in:
+20
-11
@@ -1,10 +1,18 @@
|
||||
use std::{env, net::SocketAddr};
|
||||
mod app;
|
||||
mod error;
|
||||
mod routes;
|
||||
mod service;
|
||||
mod state;
|
||||
mod storage;
|
||||
|
||||
use axum::{Json, Router, routing::get};
|
||||
use serde_json::json;
|
||||
use std::{env, net::SocketAddr, path::PathBuf};
|
||||
|
||||
use mcpaas_registry::PostgresRegistry;
|
||||
use tokio::net::TcpListener;
|
||||
use tracing::info;
|
||||
|
||||
use crate::{app::build_app, service::AdminService, state::AppState};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tracing_subscriber::fmt()
|
||||
@@ -14,9 +22,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
)
|
||||
.init();
|
||||
|
||||
let database_url = env::var("MCPAAS_DATABASE_URL")?;
|
||||
let storage_root = PathBuf::from(
|
||||
env::var("MCPAAS_STORAGE_ROOT").unwrap_or_else(|_| "/var/lib/rmcp/storage".into()),
|
||||
);
|
||||
let bind_addr = env::var("MCPAAS_ADMIN_BIND").unwrap_or_else(|_| "0.0.0.0:3001".into());
|
||||
let socket_addr: SocketAddr = bind_addr.parse()?;
|
||||
let app = Router::new().route("/health", get(health));
|
||||
let registry = PostgresRegistry::connect(&database_url).await?;
|
||||
let state = AppState {
|
||||
service: AdminService::new(registry, storage_root),
|
||||
};
|
||||
let app = build_app(state);
|
||||
let listener = TcpListener::bind(socket_addr).await?;
|
||||
|
||||
info!("admin-api listening on {}", socket_addr);
|
||||
@@ -25,10 +41,3 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn health() -> Json<serde_json::Value> {
|
||||
Json(json!({
|
||||
"service": "admin-api",
|
||||
"status": "ok"
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user