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

fix: fix 404 page bug when accessing wrong static files. #2722

Closed
wants to merge 3 commits into from
Closed

fix: fix 404 page bug when accessing wrong static files. #2722

wants to merge 3 commits into from

Conversation

Lucas-lyh
Copy link
Contributor

This #2570 issue is because starlette modify request.route['root_path'] when routing static files mount. I just reset this field when handling 404 page request.
I'm a beginner in nicegui and may miss something. On my machine, all test passed and the bug is fixed.
I also add a test for 404 page.

@rodja
Copy link
Member

rodja commented Mar 20, 2024

Interesting. Will it still work with subpath mounting? Like in our example https://github.com/zauberzeug/nicegui/tree/main/examples/nginx_subpath?

@Lucas-lyh
Copy link
Contributor Author

Interesting. Will it still work with subpath mounting? Like in our example https://github.com/zauberzeug/nicegui/tree/main/examples/nginx_subpath?

Yes!
I have to confess that I forgot to exam this situation. In my test, subpath mounting works well because prefix is assigned to X-Forwarded-Prefix in headers if exist, instead of route['root_path']. In fact because of that, 404 page bug is masked when working with subpath mounting.

@Lucas-lyh
Copy link
Contributor Author

Updated 404_test to prevent other test from being affected.

@rodja
Copy link
Member

rodja commented Mar 21, 2024

Cool. And what about sub-mounting in another app as we do in the fastAPI example: https://github.com/zauberzeug/nicegui/tree/main/examples/fastapi

@Lucas-lyh
Copy link
Contributor Author

Lucas-lyh commented Mar 21, 2024

Cool. And what about sub-mounting in another app as we do in the fastAPI example: https://github.com/zauberzeug/nicegui/tree/main/examples/fastapi

Thank you for your reminder, my fix gose wrong when working with app.run_with().
How about add a AppConfig field to save the correct root path, then use this path to generate 404page? I've tried to solve it but I'm not sure if it is reasonable.

@falkoschindler falkoschindler added this to the 1.4.19 milestone Mar 22, 2024
@falkoschindler
Copy link
Contributor

Thank you so much for your contribution, @Lucas-lyh!
Your pull request sparked the idea of @rodja's PR #2746, which seems to have solved issue #2570. 🚀

@falkoschindler falkoschindler added the bug Something isn't working label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants