-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
121 lines (109 loc) · 3.77 KB
/
main.py
File metadata and controls
121 lines (109 loc) · 3.77 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from starlette.responses import HTMLResponse
from fastapi.openapi.docs import get_swagger_ui_html
from fastapi.staticfiles import StaticFiles
from starlette.responses import FileResponse
from app.routes import edam, spdx, stats, metadata, fair_evaluation, fairsoft, search, tool, downloads, web_availability, publication
from app.helpers.utils import get_version
import logging
tags_metadata = [
{
"name": "stats",
"description": "Stats related endpoints",
},
{
"name": "tools",
"description": "Tools related endpoints",
},
{
"name": "edam",
"description": "EDAM related endpoints",
},
{
"name": "spdx",
"description": "SPDX related endpoints",
},
{
"name": "fairsoft",
"description": "FAIRsoft Evaluation related endpoints",
},
{
"name": "search",
"description": "Search related endpoints",
},
{
"name": "downloads",
"description": "Download related endpoints",
},
{
"name": "availability",
"description": "Web availability related endpoints"
},
{
"name": "publication",
"description":"Publications related endpoints"
}
]
version = get_version()
app = FastAPI(
title="Software Observatory API",
description="This is the API for the Software Observatory at [OpenEBench](https://openebench.bsc.es)",
version=version,
contact={
"name": "OpenEBench",
"url": "https://openebench.bsc.es/",
},
openapi_tags=tags_metadata,
redoc_url=None,
docs_url=None,
)
# Mount static files directory
app.mount("/static", StaticFiles(directory="static"), name="static")
# CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include Routers
app.include_router(stats.router, prefix="/stats")
app.include_router(metadata.router, prefix="/tools")
app.include_router(edam.router, prefix="/edam")
app.include_router(spdx.router, prefix="/spdx")
app.include_router(fair_evaluation.router, prefix="/fair") # deprecated
app.include_router(fairsoft.router, prefix="/fairsoft")
app.include_router(tool.router, prefix="/tool")
app.include_router(downloads.router, prefix="/downloads")
app.include_router(web_availability.router, prefix="/web-availability")
app.include_router(publication.router, prefix="/publication")
app.include_router(search.router, prefix="")
# logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
@app.get("/app")
def read_main(request: Request):
return {"message": "Hello World", "root_path": request.scope.get("root_path")}
# Route to serve the favicon
@app.get("/favicon", include_in_schema=False)
async def favicon():
return FileResponse("./static/favicon.ico")
@app.get("/docs", include_in_schema=False)
async def swagger_ui_html(req: Request) -> HTMLResponse:
root_path = req.scope.get("root_path", "").rstrip("/")
openapi_url = root_path + app.openapi_url
oauth2_redirect_url = app.swagger_ui_oauth2_redirect_url
if oauth2_redirect_url:
oauth2_redirect_url = root_path + oauth2_redirect_url
return get_swagger_ui_html(
openapi_url=openapi_url,
title=app.title + " - Swagger UI",
oauth2_redirect_url=oauth2_redirect_url,
init_oauth=app.swagger_ui_init_oauth,
swagger_favicon_url="https://observatory.openebench.bsc.es/api/favicon"
)
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, host='0.0.0.0', port=3500, log_level='debug')