|
6 | 6 | import pydantic |
7 | 7 | import sentry_sdk |
8 | 8 | import uvicorn |
9 | | -from fastapi import FastAPI, Request, Response |
| 9 | +from fastapi import FastAPI, Request, Response, openapi |
10 | 10 | from fastapi.middleware.cors import CORSMiddleware |
11 | 11 | from fastapi.middleware.gzip import GZipMiddleware |
12 | 12 | from fastapi.responses import JSONResponse |
| 13 | +from fastapi.staticfiles import StaticFiles |
13 | 14 | from scout_apm.async_.starlette import ScoutMiddleware |
14 | 15 | from sentry_sdk.integrations.asgi import SentryAsgiMiddleware |
15 | 16 |
|
|
35 | 36 | " Project page: https://github.com/ExpDev07/coronavirus-tracker-api." |
36 | 37 | ), |
37 | 38 | version="2.0.3", |
38 | | - docs_url="/", |
39 | | - redoc_url="/docs", |
| 39 | + docs_url=None, |
| 40 | + redoc_url=None, |
40 | 41 | on_startup=[setup_client_session], |
41 | 42 | on_shutdown=[teardown_client_session], |
42 | 43 | ) |
@@ -108,6 +109,31 @@ async def handle_validation_error( |
108 | 109 | # Include routers. |
109 | 110 | APP.include_router(V1, prefix="", tags=["v1"]) |
110 | 111 | APP.include_router(V2, prefix="/v2", tags=["v2"]) |
| 112 | +APP.mount("/static", StaticFiles(directory="static"), name="static") |
| 113 | + |
| 114 | +# ############## |
| 115 | +# Swagger/Redocs |
| 116 | +# ############## |
| 117 | + |
| 118 | + |
| 119 | +@APP.get("/", include_in_schema=False) |
| 120 | +async def custom_swagger_ui_html(): |
| 121 | + """Serve Swagger UI.""" |
| 122 | + return openapi.docs.get_swagger_ui_html( |
| 123 | + openapi_url=APP.openapi_url, |
| 124 | + title=f"{APP.title} - Swagger UI", |
| 125 | + oauth2_redirect_url=APP.swagger_ui_oauth2_redirect_url, |
| 126 | + swagger_js_url="/static/swagger-ui-bundle.js", |
| 127 | + swagger_css_url="/static/swagger-ui.css", |
| 128 | + ) |
| 129 | + |
| 130 | + |
| 131 | +@APP.get("/docs", include_in_schema=False) |
| 132 | +async def redoc_html(): |
| 133 | + """Serve ReDoc UI.""" |
| 134 | + return openapi.docs.get_redoc_html( |
| 135 | + openapi_url=APP.openapi_url, title=f"{APP.title} - ReDoc", redoc_js_url="/static/redoc.standalone.js", |
| 136 | + ) |
111 | 137 |
|
112 | 138 |
|
113 | 139 | # Running of app. |
|
0 commit comments