Skip to content

Commit 5b2a592

Browse files
committed
feat: configure OpenAPI docs for prod. (closes #110)
1 parent ddd5c4a commit 5b2a592

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/main.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,26 @@
2323
) + "%2Fapi%2Fauth%2Flogin%3Fredirect_path%3D%2Fapi%2Fapi%2Fdocs%2F%26redirect_fragment%3D"
2424
)
2525

26-
app = FastAPI(
27-
lifespan=database.lifespan,
28-
title="CSSS Site Backend",
29-
description=f'To login, please click <a href="{_login_link}">here</a><br><br>To logout from CAS click <a href="https://cas.sfu.ca/cas/logout">here</a>',
30-
root_path="/api"
31-
)
26+
# Enable OpenAPI docs only for local development
27+
if os.environ.get("LOCAL") == "true":
28+
app = FastAPI(
29+
lifespan=database.lifespan,
30+
title="CSSS Site Backend",
31+
description=f'To login, please click <a href="{_login_link}">here</a><br><br>To logout from CAS click <a href="https://cas.sfu.ca/cas/logout">here</a>',
32+
root_path="/api",
33+
)
34+
# if on production, disable vieweing the docs
35+
else:
36+
app = FastAPI(
37+
lifespan=database.lifespan,
38+
title="CSSS Site Backend",
39+
description=f'To login, please click <a href="{_login_link}">here</a><br><br>To logout from CAS click <a href="https://cas.sfu.ca/cas/logout">here</a>',
40+
root_path="/api",
41+
docs_url=None, # disables Swagger UI
42+
redoc_url=None, # disables ReDoc
43+
openapi_url=None # disables OpenAPI schema
44+
)
45+
3246

3347
app.include_router(auth.urls.router)
3448
app.include_router(elections.urls.router)

0 commit comments

Comments
 (0)