-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
65 lines (53 loc) · 2.1 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse, ORJSONResponse
from fastapi.middleware.cors import CORSMiddleware
import logging
from sumstats.config import (API_BASE,
APP_VERSION,
API_DESCRIPTION,
TAGS_METADATA)
from sumstats.dependencies.error_classes import APIException
import sumstats.api_v1.routers.routes as routes_v1
import sumstats.api_v2.routers.eqtl as routes_v2
logging.config.fileConfig("sumstats/log_conf.ini",
disable_existing_loggers=False)
logger = logging.getLogger(__name__)
app = FastAPI(title="eQTL Catalogue Summary Statistics API Documentation",
openapi_tags=TAGS_METADATA,
description=API_DESCRIPTION,
docs_url=f"{API_BASE}/docs",
redoc_url=None,
openapi_url=f"{API_BASE}/openapi.json",
version=APP_VERSION
)
@app.exception_handler(ValueError)
async def value_error_exception_handler(request: Request, exc: ValueError):
return JSONResponse(
status_code=400,
content={"message": str(exc)},
)
@app.exception_handler(APIException)
async def handle_custom_api_exception(request: Request,
exc: APIException):
return JSONResponse(
status_code=exc.status_code,
content={"message": exc.message},
)
# configure CORS
app.add_middleware(CORSMiddleware,
allow_origins=['*'])
# v1 API (default)
app.include_router(routes_v1.router,
prefix=API_BASE,
include_in_schema=False,
default_response_class=ORJSONResponse)
app.include_router(routes_v1.router,
prefix=f"{API_BASE}/v1",
default_response_class=ORJSONResponse,
deprecated=True,
tags=["eQTL API v1"])
# v2 API
app.include_router(routes_v2.router,
prefix=f"{API_BASE}/v2",
default_response_class=ORJSONResponse,
tags=["eQTL API v2"])