Function create_router

Source
pub fn create_router(state: AppState) -> Router
Expand description

Creates the main application router with all endpoints configured.

Sets up all HTTP routes and their corresponding handlers with the provided application state. The router includes:

  • GET / - Statistics dashboard page (live status overview)
  • GET /health - Health check endpoint
  • GET /search - Search endpoint with query parameters
  • POST /index - Domain indexing endpoint
  • POST /admin/force-index - Force immediate indexing (requires admin auth)
  • GET /admin/stats - Search statistics endpoint (requires admin auth)
  • GET /admin/top-queries - Top queries analytics endpoint (requires admin auth)

§Arguments

  • state - Application state containing all service instances

§Returns

Configured Axum router ready to be served

§Example

use search_engine_backend::{AppState, create_router, Config, StorageService, SearchService, IndexerService};
use std::sync::Arc;

let config = Arc::new(Config::from_env()?);
let storage_service = Arc::new(StorageService::new(config.clone()).await?);
let search_service = Arc::new(SearchService::new(config.clone()).await?);
let indexer_service = Arc::new(IndexerService::new(
    config.clone(),
    storage_service.clone(),
    search_service.clone()
).await?);

let app_state = AppState {
    config,
    search_service,
    storage_service,
    indexer_service,
};
let router = create_router(app_state);