Add root '/' redirect to /app and corresponding test#11
Add root '/' redirect to /app and corresponding test#11
/app and corresponding test#11Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a redirect from the root path to /app and adds a corresponding test case. The reviewer suggests using a 308 Permanent Redirect instead of a 302 Found status code to allow for browser caching and maintain the request method, along with a necessary update to the test assertion.
|
|
||
| @app.get("/", include_in_schema=False) | ||
| def root_redirect() -> RedirectResponse: | ||
| return RedirectResponse("/app", status_code=status.HTTP_302_FOUND) |
There was a problem hiding this comment.
For a permanent redirect like this, it's better to use a permanent redirect status code. This can improve performance for repeat visitors as browsers can cache the redirect. I suggest using 308 Permanent Redirect.
The 308 status code preserves the request method (GET in this case) and indicates the redirect is permanent. You will also need to update the corresponding test to expect a 308 status code.
| return RedirectResponse("/app", status_code=status.HTTP_302_FOUND) | |
| return RedirectResponse("/app", status_code=status.HTTP_308_PERMANENT_REDIRECT) |
| with stack["TestClient"](app, base_url="https://testserver") as client: | ||
| response = client.get("/", follow_redirects=False) | ||
|
|
||
| assert response.status_code == 302 |
Motivation
/appfor a smoother entry point.Description
/inapp/main.pythat returnsRedirectResponse("/app", status_code=status.HTTP_302_FOUND)and importstatusandRedirectResponse.test_root_route_redirects_to_appintests/test_auth_requester.pyto validate the redirect.Testing
tests/test_auth_requester.py::test_root_route_redirects_to_appand ran the test suite; the new test passed with the existing tests.Codex Task