Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Redirect root to prefix #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jamilraichouni
Copy link
Contributor

When CME_ROUTE_PREFIX is set, redirect root to the prefix.

@jamilraichouni jamilraichouni marked this pull request as ready for review February 20, 2025 13:20
@jamilraichouni jamilraichouni marked this pull request as draft February 20, 2025 15:04
@jamilraichouni jamilraichouni marked this pull request as ready for review February 20, 2025 15:29
When `CME_ROUTE_PREFIX` is set, redirect root to the prefix.
Comment on lines +38 to +43
if any(
(
c.ROUTE_PREFIX and not c.ROUTE_PREFIX.startswith("/"),
"/" in c.ROUTE_PREFIX and not c.ROUTE_PREFIX.replace("/", ""),
)
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the any function call here, a simple or in between is enough. Plus, or evaluates the second condition lazily.

If we additionally .rstrip("/") the ROUTE_PREFIX in constants.py:47, a string consisting only of forward slashes will become an empty string, which is valid input. Given that, we can drastically simplify this condition to:

if c.ROUTE_PREFIX and not c.ROUTE_PREFIX.startswith("/"):

Comment on lines +38 to +45
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hangs in live mode for some reason, haven't yet investigated though.

"/" in c.ROUTE_PREFIX and not c.ROUTE_PREFIX.replace("/", ""),
)
):
logger.error("Route prefix is invalid.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.error("Route prefix is invalid.")
logger.error("Invalid route prefix: %r", c.ROUTE_PREFIX)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants