-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
48 lines (36 loc) · 1.16 KB
/
app.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
37
38
39
40
41
42
43
44
45
46
47
48
from fastapi import FastAPI, Request, HTTPException
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from service.router import api_router
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # allow all sources
allow_methods=["GET"], # allow only GET method
allow_headers=["*"], # allow all header
)
app.include_router(api_router, prefix="/v3")
@app.exception_handler(HTTPException)
async def http_exception_handler(request: Request, exc: HTTPException):
return JSONResponse(
status_code=exc.status_code,
content={
"error": "HTTP Error",
"message": exc.detail,
},
)
@app.exception_handler(Exception)
async def general_exception_handler(request: Request, exc: Exception):
return JSONResponse(
status_code=500,
content={
"error": "Internal Server Error",
"message": str(exc),
},
)
@app.get("/")
async def root():
return { "project": "https://github.com/alxiw/punkapi" }
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=5000, log_level="debug")