refactor: use api::add_routes() and docs::add_routes() to register server routes

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-12 15:01:40 -03:00
parent 6869b08a77
commit 68c5514a44
2 changed files with 13 additions and 6 deletions

View File

@@ -1,6 +1,5 @@
use anyhow::Result; use anyhow::Result;
use axum::{ use axum::{
routing::get,
Router, Router,
}; };
use clap::Command; use clap::Command;
@@ -68,6 +67,10 @@ async fn run_server(
) )
.with_state(state); .with_state(state);
// Add API and documentation routes
let app = api::add_routes(app);
let app = docs::add_routes(app);
let addr: SocketAddr = if config.address.starts_with('/') || config.address.starts_with("./") { let addr: SocketAddr = if config.address.starts_with('/') || config.address.starts_with("./") {
// Unix socket - not supported by axum directly, fall back to TCP // Unix socket - not supported by axum directly, fall back to TCP
warn!("Unix sockets not yet implemented, falling back to TCP on 127.0.0.1:8080"); warn!("Unix sockets not yet implemented, falling back to TCP on 127.0.0.1:8080");

View File

@@ -1,10 +1,14 @@
use axum::response::{Html, Json}; use axum::response::{Html, Json};
use serde_json::json; use serde_json::json;
use serde_json::Value;
// Remove the invalid imports - we'll access the OpenAPI specs differently use crate::modes::server::common::AppState;
// For now, we'll create a simplified version that doesn't depend on those functions use axum::{
routing::get,
Router,
};
pub async fn handle_openapi() -> Json<serde_json::Value> { pub async fn handle_openapi() -> Json<Value> {
let openapi_spec = json!({ let openapi_spec = json!({
"openapi": "3.0.0", "openapi": "3.0.0",
"info": { "info": {
@@ -85,6 +89,6 @@ pub async fn handle_swagger_ui() -> Html<&'static str> {
pub fn add_routes(router: Router<AppState>) -> Router<AppState> { pub fn add_routes(router: Router<AppState>) -> Router<AppState> {
router router
// Documentation endpoints // Documentation endpoints
.route("/openapi.json", get(docs::handle_openapi)) .route("/openapi.json", get(handle_openapi))
.route("/swagger/", get(docs::handle_swagger_ui)) .route("/swagger/", get(handle_swagger_ui))
} }