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 async_graphql_axum::{GraphQLRequest, GraphQLResponse, GraphQLSubscription};
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{FromRef, State},
|
extract::{FromRef, State},
|
||||||
|
http::{Method, StatusCode},
|
||||||
response::{Html, IntoResponse},
|
response::{Html, IntoResponse},
|
||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
@ -95,22 +96,28 @@ pub async fn create_router(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let router = ReverseProxy::new("/api", &config.tile_server_url.as_str());
|
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()
|
Router::new()
|
||||||
.route("/", get(graphql_playground))
|
};
|
||||||
.route("/graphql", get(graphql_playground).post(graphql_handler))
|
|
||||||
// .route_layer(
|
router_s
|
||||||
// RateLimitLayer::<RealIp>::builder()
|
.route("/graphql", get(not_found).post(graphql_handler))
|
||||||
// .with_route(
|
.route_layer(
|
||||||
// (Method::GET, "/graphql"),
|
RateLimitLayer::<RealIp>::builder()
|
||||||
// Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
|
.with_route(
|
||||||
// )
|
(Method::GET, "/graphql"),
|
||||||
// .with_route(
|
Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
|
||||||
// (Method::POST, "/graphql"),
|
)
|
||||||
// Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
|
.with_route(
|
||||||
// )
|
(Method::POST, "/graphql"),
|
||||||
// .with_gc_interval(1000)
|
Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
|
||||||
// .default_handle_error(),
|
)
|
||||||
// )
|
.with_gc_interval(1000)
|
||||||
|
.default_handle_error(),
|
||||||
|
)
|
||||||
.route_service("/ws", GraphQLSubscription::new(schema))
|
.route_service("/ws", GraphQLSubscription::new(schema))
|
||||||
.layer(CorsLayer::permissive())
|
.layer(CorsLayer::permissive())
|
||||||
.merge(router)
|
.merge(router)
|
||||||
@ -133,3 +140,7 @@ async fn graphql_handler(
|
|||||||
async fn graphql_playground() -> impl IntoResponse {
|
async fn graphql_playground() -> impl IntoResponse {
|
||||||
Html(playground_source(GraphQLPlaygroundConfig::new("/graphql")))
|
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