This commit is contained in:
parent
f521c2102c
commit
22f57d1c7e
41
src/app.rs
41
src/app.rs
@ -10,6 +10,7 @@ use async_graphql::{
|
||||
use async_graphql_axum::{GraphQLRequest, GraphQLResponse, GraphQLSubscription};
|
||||
use axum::{
|
||||
extract::{FromRef, State},
|
||||
http::{Method, StatusCode},
|
||||
response::{Html, IntoResponse},
|
||||
routing::get,
|
||||
Router,
|
||||
@ -95,22 +96,28 @@ pub async fn create_router(
|
||||
};
|
||||
|
||||
let router = ReverseProxy::new("/api", &config.tile_server_url.as_str());
|
||||
|
||||
let router_s = if cfg!(debug_assertions) {
|
||||
Router::new().route("/", get(graphql_playground))
|
||||
} else {
|
||||
Router::new()
|
||||
.route("/", get(graphql_playground))
|
||||
.route("/graphql", get(graphql_playground).post(graphql_handler))
|
||||
// .route_layer(
|
||||
// RateLimitLayer::<RealIp>::builder()
|
||||
// .with_route(
|
||||
// (Method::GET, "/graphql"),
|
||||
// Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
|
||||
// )
|
||||
// .with_route(
|
||||
// (Method::POST, "/graphql"),
|
||||
// Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
|
||||
// )
|
||||
// .with_gc_interval(1000)
|
||||
// .default_handle_error(),
|
||||
// )
|
||||
};
|
||||
|
||||
router_s
|
||||
.route("/graphql", get(not_found).post(graphql_handler))
|
||||
.route_layer(
|
||||
RateLimitLayer::<RealIp>::builder()
|
||||
.with_route(
|
||||
(Method::GET, "/graphql"),
|
||||
Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
|
||||
)
|
||||
.with_route(
|
||||
(Method::POST, "/graphql"),
|
||||
Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
|
||||
)
|
||||
.with_gc_interval(1000)
|
||||
.default_handle_error(),
|
||||
)
|
||||
.route_service("/ws", GraphQLSubscription::new(schema))
|
||||
.layer(CorsLayer::permissive())
|
||||
.merge(router)
|
||||
@ -133,3 +140,7 @@ async fn graphql_handler(
|
||||
async fn graphql_playground() -> impl IntoResponse {
|
||||
Html(playground_source(GraphQLPlaygroundConfig::new("/graphql")))
|
||||
}
|
||||
|
||||
async fn not_found() -> impl IntoResponse {
|
||||
(StatusCode::NOT_FOUND, "Not Found")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user