rate limit
Some checks are pending
Docker Build and Push / build (push) Waiting to run

This commit is contained in:
Tsuki 2025-08-17 20:11:51 +08:00
parent f521c2102c
commit 22f57d1c7e

View File

@ -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());
Router::new()
.route("/", get(graphql_playground)) let router_s = if cfg!(debug_assertions) {
.route("/graphql", get(graphql_playground).post(graphql_handler)) Router::new().route("/", get(graphql_playground))
// .route_layer( } else {
// RateLimitLayer::<RealIp>::builder() Router::new()
// .with_route( };
// (Method::GET, "/graphql"),
// Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()), router_s
// ) .route("/graphql", get(not_found).post(graphql_handler))
// .with_route( .route_layer(
// (Method::POST, "/graphql"), RateLimitLayer::<RealIp>::builder()
// Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()), .with_route(
// ) (Method::GET, "/graphql"),
// .with_gc_interval(1000) Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
// .default_handle_error(), )
// ) .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)) .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")
}