Skip to content

Commit 7ddbe66

Browse files
committed
fix(routes): compose the Laravel 11+ withRouting api prefix into Route paths (DeusData#1146)
Laravel 11+ registers its route files in bootstrap/app.php through Application::configure()->withRouting(web: ..., api: ..., apiPrefix: ...) and mounts every file passed as `api:` under `apiPrefix` (default 'api'). That prefix lives in a different file than the routes, so per-file extraction -- which already composes the in-file Route::prefix()->group() chain (DeusData#952) -- minted `GET /users/me` for a route Laravel serves at `GET /api/users/me`. The Route qualified_name is the join key for cross-repo HTTP matching, so real callers of /api/... never linked, and an api route could silently merge with a same-path web route. Fix: a small Laravel mount resolver, src/pipeline/laravel_routing.c. For each PHP file that registers a path-shaped route, both route passes (the sequential calls pass and the parallel resolver) look up the nearest ancestor bootstrap/app.php once, parse it with the PHP grammar, and, when its withRouting(api: ...) names that file, prepend the apiPrefix to every Route minted from it. Only source facts are used: an `api:` entry must be a __DIR__ / dirname(__DIR__) concatenation or a base_path() call over a string literal (single path or array), and a given apiPrefix must be a string literal. A non-literal apiPrefix, positional arguments or a `using:` callback leave the paths untouched, the `web:` file is never prefixed, and nothing is inferred from file names. The lookup keys only on the repo path and the file path, so full, incremental and delta runs compose the same identity. Proof (origin/main 1f9b4db vs this change, same machine): - krayin/laravel-crm @03ebedd7: GET /user -> GET /api/user; the other four Route nodes are unchanged. - filamentphp/demo @d5b618a1: GET /user -> GET /api/user. - laravelio/laravel.io @24be4893: the api.php POST '/' inside prefix('articles') was merged into web.php's POST /articles node; it is now its own POST /api/articles (39 -> 40 Route nodes, every web route unchanged). - Cross-repo: a TypeScript client calling axios.get('/api/users/me') and axios.post('/api/orders') against a Laravel 11 server: CROSS_HTTP_CALLS 0 -> 2. Tests (edge_types_probe): default api prefix plus the composed qualified_name, a custom multi-segment apiPrefix with the array form of `api:`, the `web:` file stays unprefixed, a Laravel <= 10 RouteServiceProvider control stays as it is, a non-literal apiPrefix is left alone, and the parallel resolver with the app in a monorepo subdirectory. The four bug tests were RED 3x before the fix, pass with it, and go RED again with only the composition reverted. Fixes DeusData#1146 Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent bedbc0a commit 7ddbe66

6 files changed

Lines changed: 646 additions & 24 deletions

File tree

‎Makefile.cbm‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ PIPELINE_SRCS = \
436436
src/pipeline/lsp_surface.c \
437437
src/pipeline/pipeline_delta.c \
438438
src/pipeline/path_alias.c \
439+
src/pipeline/laravel_routing.c \
439440
src/pipeline/registry.c \
440441
src/pipeline/pipeline.c \
441442
src/pipeline/pipeline_incremental.c \

0 commit comments

Comments
 (0)