Core: Register CORS middleware before index.json route#33728
Merged
valentinpalkovic merged 1 commit intostorybookjs:nextfrom Feb 2, 2026
Merged
Core: Register CORS middleware before index.json route#33728valentinpalkovic merged 1 commit intostorybookjs:nextfrom
valentinpalkovic merged 1 commit intostorybookjs:nextfrom
Conversation
Fixes storybookjs#33724 The /index.json endpoint was missing CORS headers because the route handler was registered before the CORS middleware. This broke Storybook Composition when composing local Storybooks running on different ports. The fix moves the middleware registration order so that: 1. Compression middleware is applied first 2. extendServer callback is called 3. CORS middleware (getAccessControlMiddleware) is registered 4. Caching middleware is registered 5. Route handlers are registered (including /index.json) This ensures all routes receive proper CORS headers, fixing the 'Access-Control-Allow-Origin' header missing error for /index.json.
Contributor
📝 WalkthroughWalkthroughThe dev server's Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
valentinpalkovic
approved these changes
Feb 2, 2026
This was referenced Feb 2, 2026
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 183 | 183 | 0 |
| Self size | 779 KB | 776 KB | 🎉 -3 KB 🎉 |
| Dependency size | 67.62 MB | 67.57 MB | 🎉 -50 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
create-storybook
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 50 | 50 | 0 |
| Self size | 1.04 MB | 1000 KB | 🎉 -44 KB 🎉 |
| Dependency size | 36.93 MB | 36.93 MB | 🎉 -6 KB 🎉 |
| Bundle Size Analyzer | node | node |
@storybook/preact
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 2 | 2 | 0 |
| Self size | 23 KB | 16 KB | 🎉 -7 KB 🎉 |
| Dependency size | 32 KB | 32 KB | 0 B |
| Bundle Size Analyzer | Link | Link |
Merged
1 task
This was referenced Mar 18, 2026
Merged
1 task
This was referenced Mar 18, 2026
This was referenced Mar 18, 2026
1 task
1 task
This was referenced Apr 8, 2026
Closed
1 task
This was referenced Apr 12, 2026
1 task
This was referenced Apr 17, 2026
Open
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.
Description
Fixes #33724
The
/index.jsonendpoint was missing CORS headers because the route handler was registered before the CORS middleware. This broke Storybook Composition when composing local Storybooks running on different ports.Root Cause
The middleware registration order in
dev-server.tswas:registerIndexJsonRoute()❌ Route registered firstapp.use(compression(...))app.use(getAccessControlMiddleware(...))❌ CORS middleware registered afterSince the
/index.jsonroute handler sends the response directly without callingnext(), the CORS middleware never had a chance to add headers.Solution
Moved the middleware registration order so that CORS headers are applied to all routes:
app.use(compression(...))app.use(getAccessControlMiddleware(...))✅ CORS middleware firstapp.use(getCachingMiddleware())registerIndexJsonRoute()✅ Route registered afterTesting
/index.jsonAccess-Control-Allow-Origin: *header is returnedWhat this fixes
/index.jsonfrom a composed StorybookSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.