Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ CORS_ORIGINS=[]
# DB_USER=nene2
# DB_PASSWORD=secret

# レートリミット(APP_ENV=local では未設定時オフ。有効化する場合のみ)
# THROTTLE_ENABLED=true
# THROTTLE_LIMIT=60
# THROTTLE_WINDOW=60

# デフォルト値
DB_ADAPTER=sqlite
DB_NAME=:memory:
Expand Down
3 changes: 3 additions & 0 deletions src/example/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def _build_repositories(cfg: AppSettings) -> _Repos:

def create_app(settings: AppSettings | None = None) -> FastAPI:
cfg = settings or AppSettings()
# Local dev / consumer FT: throttle off unless THROTTLE_ENABLED is set (nene2-python#592).
if cfg.app_env == "local" and os.getenv("THROTTLE_ENABLED") is None:
cfg = cfg.model_copy(update={"throttle_enabled": False})
setup_logging(cfg.app_env)

app = FastAPI(
Expand Down
15 changes: 15 additions & 0 deletions tests/example/test_local_throttle_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Local example app disables throttle by default (FT / dev ergonomics)."""

from fastapi.testclient import TestClient

from example.app import create_app
from nene2.config import AppSettings


def test_local_app_allows_burst_without_429() -> None:
cfg = AppSettings(app_env="local")
assert cfg.throttle_enabled is True # settings default; create_app adjusts
client = TestClient(create_app(cfg))
for _ in range(30):
r = client.get("/examples/ping")
assert r.status_code == 200, r.text
Loading