-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
31 lines (22 loc) · 792 Bytes
/
main.py
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
from fastapi import FastAPI
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.util import get_remote_address
from slowapi.errors import RateLimitExceeded
from starlette.requests import Request
import uvicorn
from dotenv import load_dotenv, find_dotenv
from app.internal import admin
from app.routers import item
load_dotenv(find_dotenv())
limiter = Limiter(key_func=get_remote_address)
app = FastAPI()
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
app.include_router(admin.router)
app.include_router(item.router)
@app.get("/ping")
@limiter.limit("1/second")
async def root(request: Request):
return {"message": "OK"}
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", reload=True)