fix(dev-server): return 404 status code for non-existent pages #11476
+74
−0
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
Fixes #11095 - Dev server now returns proper 404 status code for non-existent pages instead of 200.
Problem
The dev server's
historyApiFallbackconfiguration was serving the SPA for all routes with HTTP 200 status, even for non-existent pages. This made debugging difficult and caused issues when browsers attempted to load non-existent CSS/JS files (receiving HTML content instead).Solution
Added middleware (
docusaurus-404-status) that:Detection Strategy
The middleware identifies 404 pages using multiple patterns:
hero__titleclass (from NotFound component structure)This approach supports:
Performance Considerations
Limitations
Custom 404 pages that completely remove all "404" and "not found" text may not be detected. Users customizing their NotFound component should ensure it includes recognizable 404 indicators.
Test Plan
Tested manually:
/foo/bar/baz) returns 404Related