collet 0.1.0

Relentless agentic coding orchestrator with zero-drop agent loops
Documentation
//! Serve the embedded Svelte SPA build via rust-embed.

use axum::http::{StatusCode, Uri, header};
use axum::response::{Html, IntoResponse, Response};
use rust_embed::Embed;

#[derive(Embed)]
#[folder = "web/build"]
struct Assets;

/// Serve embedded static files; fall back to index.html for SPA routing.
pub async fn serve(uri: Uri) -> Response {
    let path = uri.path().trim_start_matches('/');

    // Try exact file first
    if let Some(file) = Assets::get(path) {
        let mime = mime_guess::from_path(path).first_or_octet_stream();
        (
            StatusCode::OK,
            [(header::CONTENT_TYPE, mime.as_ref())],
            file.data,
        )
            .into_response()
    } else {
        // SPA fallback: serve index.html
        match Assets::get("index.html") {
            Some(file) => Html(file.data).into_response(),
            None => (StatusCode::NOT_FOUND, "Frontend not built").into_response(),
        }
    }
}