puerto 0.10.0

Puerto — Rust full-stack DDD framework CLI. Scaffolds Clean Architecture projects with auto-wired DI, SQLx support, and zero manual wiring. Formerly puerto-framework.
// AUTO-GENERATED by puerto. Edit puerto.toml, then run `puerto generate bootstrap`.
use std::sync::Arc;

use business::application::greeting::get_greeting::GetGreetingUseCaseImpl;

use business::domain::greeting::repository::GreetingRepositoryTrait;
use infrastructure::greeting::repository::InMemoryGreetingRepository;

use poem::{EndpointExt, Route, get, middleware::{Cors, Tracing}};
use poem_openapi::OpenApiService;

use crate::api::greeting::routes::GreetingApi;

pub async fn build_app() -> impl poem::Endpoint {
    let get_greeting = Arc::new(GetGreetingUseCaseImpl { repository: Arc::new(InMemoryGreetingRepository::new()) as Arc<dyn GreetingRepositoryTrait> });
    let greeting_api = GreetingApi { get_greeting };

    let port = std::env::var("SERVICE_PORT").unwrap_or_else(|_| "8080".to_string());
    let api_service = OpenApiService::new(
        greeting_api,
        env!("CARGO_PKG_NAME"),
        env!("CARGO_PKG_VERSION"),
    )
    .server(format!("http://localhost:{port}/api"));
    let ui = api_service.swagger_ui();

    let cors_origins = std::env::var("CORS_ALLOWED_ORIGINS").unwrap_or_default();
    let mut cors = Cors::new();
    for origin in cors_origins.split(',').map(str::trim).filter(|s| !s.is_empty()) {
        cors = cors.allow_origin(origin);
    }

    Route::new()
        .at("/health", get(crate::health::liveness))
        .at(
            "/health/ready",
            get(poem::endpoint::make_sync(|_| crate::health::readiness(true))),
        )
        .nest("/api", api_service)
        .nest("/", ui)
        .with(Tracing)
        .with(cors)
}