-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
36 lines (30 loc) · 1.09 KB
/
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
32
33
34
35
36
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from api_analytics.fastapi import Analytics
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.util import get_remote_address
from slowapi.errors import RateLimitExceeded
from slowapi.middleware import SlowAPIMiddleware
from routes import sites
from utils import env
limiter = Limiter(key_func=get_remote_address, default_limits=["30/minute"])
app = FastAPI(title="StopMalwareContent API",
description="The official StopMalwareContent API, to send you json responses.",
version="1.1")
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
origins = ["*"]
app.include_router(sites.router)
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.add_middleware(SlowAPIMiddleware)
app.add_middleware(Analytics, api_key=env.ANALYTICS_API_KEY)
@app.get("/")
@limiter.exempt
def read_root():
return {f"StopMalwareContent API v{app.version}"}