Skip to content

Commit

Permalink
feat: Redirect root to prefix
Browse files Browse the repository at this point in the history
When `CME_ROUTE_PREFIX` is set, redirect root to the prefix.
  • Loading branch information
jamilraichouni committed Feb 20, 2025
1 parent 399599d commit 42623b5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions capella_model_explorer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import contextlib
import logging
import pathlib
import sys
import tempfile
import time
import traceback
Expand Down Expand Up @@ -34,6 +35,15 @@
logger.info("\tCapella model: '%s'", c.MODEL)
logger.info("\tTemplates directory: '%s'", c.TEMPLATES_DIR)

if any(
(
c.ROUTE_PREFIX and not c.ROUTE_PREFIX.startswith("/"),
"/" in c.ROUTE_PREFIX and not c.ROUTE_PREFIX.replace("/", ""),
)
):
logger.error("Route prefix is invalid.")
sys.exit(1)


@contextlib.asynccontextmanager
async def lifespan(_):
Expand Down Expand Up @@ -89,6 +99,13 @@ def metrics() -> t.Any:
)


@app.get("/")
def prefix_redirect() -> t.Any:
if c.ROUTE_PREFIX:
return fh.RedirectResponse(url=app.url_path_for("main_home"))
return home()


@ar.get("/", name="main_home")
def home() -> t.Any:
"""Show home/ landing page with all reports in categories."""
Expand Down

0 comments on commit 42623b5

Please sign in to comment.