Answer unmatched /api paths with 404 ProblemDetails instead of the SPA bundle - #217
Merged
Merged
Conversation
…A bundle
MapFallbackToFile claims every path no endpoint matched, which included unmatched
/api paths. A typo, an endpoint that moved, or a route parameter failing its type
constraint all answered 200 text/html with index.html, and every client read that
as success. Measured against a lab install: GET /api/triggers and GET
/api/global-variables/not-a-guid both returned a 200 HTML page, which np, the MCP
server and the SPA's own error handling each accepted as a valid response body. A
missing endpoint is precisely the failure that has to be loud, and swallowing it
also hides routing regressions from tests.
A dedicated MapFallback("/api/{**rest}") now returns 404 ProblemDetails with
code NOT_FOUND. Its literal prefix outranks the SPA catch-all, so the scope is
exactly the API surface; deep links the SPA owns still reach index.html. Declared
AllowAnonymous so a missing endpoint reports as missing rather than as
unauthorized -- 401 vs 404 was already distinguishable before, so this exposes
nothing new.
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.
Problem
MapFallbackToFile("index.html")matches whatever no endpoint claimed — including unmatched/apipaths. A typo, an endpoint that moved, or a route parameter that failed its type constraint all answered200 text/htmlwith the SPA bundle.Measured against a 1.2.6 lab install:
GET /api/triggers200 text/html(SPA)GET /api/secrets200 text/html(SPA)GET /api/global-variables/not-a-guid200 text/html(SPA)GET /api/workflows/<unknown-guid>404 application/problem+json✅ (a real action answered)np, the MCP server and the SPA's own error handling all treated the HTML page as a valid response body. A missing endpoint is exactly the failure that must be loud — and swallowing it also hides routing regressions from tests.Change
A dedicated
MapFallback("/api/{**rest}")registered before the SPA catch-all returns404ProblemDetails withcode: NOT_FOUND. Its literal prefix outranks the SPA's{*path:nonfile}, so the scope is exactly the API surface — deep links the SPA owns (/workflows/<id>and friends) still reachindex.html.AllowAnonymous, so a missing endpoint reports as missing rather than as unauthorized. 401-vs-200 was already distinguishable before, so this exposes nothing new.Tests
tests/NodePilot.Api.Tests/Hosting/ApiNotFoundFallbackTests.cs— 5 cases over the realProgram.cspipeline: three unmatched shapes (unknown path, real prefix without an action, failed:guidconstraint) assert 404 +application/problem+json+ no<!doctype; one asserts a non-API deep link still routes to the SPA fallback; one asserts a matched endpoint is unshadowed.Ran:
dotnet test tests/NodePilot.Api.Tests— 2407 passed.