mirror of
https://github.com/LeNei/axum-sqlx-template.git
synced 2026-02-13 22:56:19 +00:00
20 lines
545 B
Rust
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)
|
|
}
|