refactor: table-driven endpoint dispatch - #130
Merged
Merged
Conversation
Replace the if/elif chains in do_POST/do_GET/do_DELETE with one class-level route table per HTTP method plus a four-line _dispatch(). Adding an endpoint is now one table row, and the server-side action set is machine-readable - a new coverage test cross-checks it against api.php's switch so an endpoint added on the Python side can no longer silently 404 on shared hosting. The action string is only ever used as a dict key; only hardcoded table values reach getattr. Static-file precedence in do_GET, both URL dialects, the save_delete POST compatibility row, and the 404 fallthrough are preserved exactly.
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.
What
Replaces the
if/elifchains indo_POST/do_GET/do_DELETEwith one class-level route table per HTTP method (_POST_ROUTES/_GET_ROUTES/_DELETE_ROUTES, action → handler-method name) and a four-line_dispatch(). Theconfig/pinginline branches became tiny_config/_pingmethods.Adding an endpoint is now one table row — and the server-side action set is machine-readable.
New guard test
test_server_routes_are_routed_by_php_proxycross-checks the route tables againstapi.php's switch: an endpoint added on the Python side but forgotten in the PHP shim previously silently 404'd only on shared hosting (the existing coverage test only checked frontend-called actions). This closes that gap.Preserved exactly
save_deletePOST compatibility row with its commentdo_GET(checked before action resolution)/api/<action>andapi.php?action=) via the untouched_resolve_action{"error": "not found"}404getattrTests
487 backend tests OK (486 + the new guard).