use super::handlers::my_test::post_my_test;
use tower_http::{cors::CorsLayer, trace::TraceLayer};
use std::io::Error;
use axum::routing::post;

pub async fn init_api(
    
) -> Result<(), Error> {
    let cors = CorsLayer::permissive();
    let app = axum::Router::new()
        .route(
            "/api/v1/test",
            post(post_my_test)
        )
        .layer(cors)
        .layer(TraceLayer::new_for_http());
    
    let listener = tokio::net::TcpListener::bind("0.0.0.0:3001").await?;
    axum::serve(listener, app).await?;

    open::that("http://localhost:3001")?;

    Ok(())
}