forked from Trustless-OSS/Toss-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rs
More file actions
34 lines (28 loc) · 855 Bytes
/
Copy pathapp.rs
File metadata and controls
34 lines (28 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use axum::{routing::get, Json, Router};
use serde::Serialize;
use tower_http::cors::CorsLayer;
use tower_http::trace::TraceLayer;
use crate::{routes, state::AppState};
#[derive(Serialize)]
struct RootResponse {
service: &'static str,
status: &'static str,
message: &'static str,
}
async fn root_handler() -> Json<RootResponse> {
Json(RootResponse {
service: "trustless-oss-backend",
status: "ok",
message: "Trustless-OSS Rust backend is running.",
})
}
pub fn build_app(state: AppState) -> Router {
// Configure CORS to allow frontend requests
let cors = CorsLayer::permissive();
let router: Router<AppState> = Router::new()
.route("/", get(root_handler))
.merge(routes::router())
.layer(cors)
.layer(TraceLayer::new_for_http());
router.with_state(state)
}