//! Serve the AFI fixture under axum on `PORT` env var (or 8765 default).
//! Used by the wire-parity test as the third-backend probe target.

use axum::Router;

#[tokio::main]
async fn main() {
    // Keep the fixture's linkme statics alive by touching one of its
    // symbols (the bin would otherwise dead-strip the library crate).
    let _ = afi_rust_app::echo;

    let port: u16 = std::env::var("PORT")
        .ok()
        .and_then(|s| s.parse().ok())
        .unwrap_or(8765);

    let app = Router::new().nest("/api/mizan", mizan_axum::router_stateless());

    let bind = format!("127.0.0.1:{port}");
    let listener = tokio::net::TcpListener::bind(&bind)
        .await
        .unwrap_or_else(|e| panic!("bind {bind}: {e}"));
    eprintln!("afi_rust_app listening on http://{bind}");
    axum::serve(listener, app).await.unwrap();
}
