Repository navigation
Add --root_app option to serve any app at / - #1070
Open
mkostrikin wants to merge 1 commit into
Open
mkostrikin wants to merge 1 commit into
mkostrikin wants to merge 1 commit into
Conversation
Until now only the app named _default could handle requests at /;
every other app was always mounted under /{app_name}/. The usual
workaround was to symlink apps/_default to the real app.
`py4web run --root_app myapp apps` now chooses which app is mounted
at / (routes and static files without the /{app_name} prefix). The
value is exported as PY4WEB_ROOT_APP, so it also works with
wsgi(root_app=...) and reaches server workers. It defaults to
_default, so existing setups are unchanged; when another app is
chosen, _default is served at /_default/ like any other app.
- core: add get_root_app_name()/is_root_app() and use them in
action route registration, static routes, URL() and the lazy
reloader hook instead of the hardcoded "_default"
- run: warn at startup if the chosen root app is not loaded
- docs: document --root_app in chapter 3 and 5
- tests: add tests/test_root_app.py
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Right now only the app named
_defaultcan handle requests at/. Every other app is always mounted under/{app_name}/, and the usual workaround is to symlinkapps/_defaultto the real app.This PR adds a
runoption that picks which app is served at/:The chosen app's actions and static files are then served without the
/{app_name}prefix, andURL()builds links to match. The default is still_default, so existing setups behave exactly as before.Changes
py4web/core.py--root_appoption onrun, defaulting to_default. Like the otherrunoptions, it is exported asPY4WEB_ROOT_APP, so it also works withwsgi(root_app=...)and reaches server workers.get_root_app_name()/is_root_app(). They replace the hardcoded"_default"in five places: action route registration, static file routes,URL()(two places), and the lazy reloader hook.runprints a warning at startup.--root_appis documented in chapter 3 (options listing, explanation, and the Default-app note, which no longer suggests the symlink) and in chapter 5 (routes without a prefix). The translated.pofiles are left for the regular translation update.tests/test_root_app.pywith 12 tests covering name resolution,URL()prefixes, action and static route registration, the reloader fallback, the CLI option and environment export, andwsgi(root_app=...).Behaviour notes
--root_app todo, the_defaultapp (if present) is served at/_default/like any other app.URL()adjust automatically. Paths hardcoded as/todo/...in templates or JS do not._defaulttoday, a route in the root app that has the same name as another app (e.g._dashboard) collides with that app.Testing
make test: 136 passed (the existing tests plus the 12 new ones).py4web run apps --root_app todo:/serves todo, and its links point to/static/..../static/js/utils.jsreturns 200./todo/returns 404./_default/still serves the default app.🤖 Generated with Claude Code