Spaces:
Build error
Build error
Delete main.py
Browse files
main.py
DELETED
|
@@ -1,56 +0,0 @@
|
|
| 1 |
-
import logging
|
| 2 |
-
from fastapi import FastAPI, Depends
|
| 3 |
-
from fastapi.responses import JSONResponse
|
| 4 |
-
from problemsolution.urls import api
|
| 5 |
-
from problemsolution.setting import settings
|
| 6 |
-
from fastapi_pagination import add_pagination
|
| 7 |
-
|
| 8 |
-
from fastapi_limiter import FastAPILimiter
|
| 9 |
-
from fastapi_limiter.depends import RateLimiter
|
| 10 |
-
import redis.asyncio as aioredis
|
| 11 |
-
from fastapi import FastAPI
|
| 12 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 13 |
-
from problemsolution.utils.exception_handler import register_error_handlers
|
| 14 |
-
|
| 15 |
-
app = FastAPI(title=settings.APP_NAME, version=settings.APP_VERSION)
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
origins = [
|
| 19 |
-
"http://127.0.0.1:8001",
|
| 20 |
-
"http://localhost:8001",
|
| 21 |
-
"https://medicalscheduler.onrender.com",
|
| 22 |
-
]
|
| 23 |
-
|
| 24 |
-
app.add_middleware(
|
| 25 |
-
CORSMiddleware,
|
| 26 |
-
allow_origins=origins,
|
| 27 |
-
allow_credentials=True,
|
| 28 |
-
allow_methods=["*"],
|
| 29 |
-
allow_headers=["*"],
|
| 30 |
-
)
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
app.include_router(api)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
@app.on_event("startup")
|
| 37 |
-
async def startup():
|
| 38 |
-
redis = await aioredis.from_url("redis://localhost", encoding="utf-8", decode_responses=True)
|
| 39 |
-
await FastAPILimiter.init(redis)
|
| 40 |
-
|
| 41 |
-
@app.exception_handler(Exception)
|
| 42 |
-
async def global_exception_handler(request, exc: Exception):
|
| 43 |
-
logging.error(f"Unhandled exception: {exc}", exc_info=True)
|
| 44 |
-
return JSONResponse(status_code=500, content={"detail": "Internal Server Error"})
|
| 45 |
-
|
| 46 |
-
register_error_handlers(app)
|
| 47 |
-
# Example endpoint with rate limiting
|
| 48 |
-
@app.get("/limited", dependencies=[Depends(RateLimiter(times=5, seconds=60))])
|
| 49 |
-
async def limited_endpoint():
|
| 50 |
-
return {"message": "This endpoint is limited to 5 requests per 60 seconds"}
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
async def user_identifier(request, _: str):
|
| 54 |
-
return request.state.user.id
|
| 55 |
-
|
| 56 |
-
add_pagination(app)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|