mirror of
https://github.com/LeNei/axum-sqlx-template.git
synced 2026-02-13 22:56:19 +00:00
base inertia setup
This commit is contained in:
22
src/api/mod.rs
Normal file
22
src/api/mod.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
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(api_context: ApiContext) -> Router {
|
||||
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)
|
||||
.with_state(api_context)
|
||||
}
|
||||
Reference in New Issue
Block a user