-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: master
Are you sure you want to change the base?
Conversation
10db603
to
a4ee213
Compare
a4ee213
to
b731598
Compare
b731598
to
b1d7c8a
Compare
When `CME_ROUTE_PREFIX` is set, redirect root to the prefix.
b1d7c8a
to
42623b5
Compare
if any( | ||
( | ||
c.ROUTE_PREFIX and not c.ROUTE_PREFIX.startswith("/"), | ||
"/" in c.ROUTE_PREFIX and not c.ROUTE_PREFIX.replace("/", ""), | ||
) | ||
): |
There was a problem hiding this comment.
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("/"):
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) |
There was a problem hiding this comment.
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.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.error("Route prefix is invalid.") | |
logger.error("Invalid route prefix: %r", c.ROUTE_PREFIX) |
When
CME_ROUTE_PREFIX
is set, redirect root to the prefix.