Files
axum-sqlx-template/src/api/mod.rs
2025-03-28 15:18:59 +01:00

20 lines
545 B
Rust

use axum::{Router, routing::get};
use http::{Method, StatusCode};
use tower_http::cors::{Any, CorsLayer};
use crate::config::ApiContext;
#[tracing::instrument(name = "Ping")]
async fn ping() -> StatusCode {
StatusCode::OK
}
pub fn routes() -> Router<ApiContext> {
let cors = CorsLayer::new()
// allow `GET` and `POST` when accessing the resource
.allow_methods([Method::GET, Method::POST])
// allow requests from any origin
.allow_origin(Any);
Router::new().route("/ping", get(ping)).layer(cors)
}