Skip to content

feat: streamline setupMiddlewares usage #5463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2025
Merged

Conversation

chenjiahan
Copy link
Member

Summary

The dev.setupMiddlewares requires the user to pass an array which is redundant.

This PR allows dev.setupMiddlewares to pass a function directly to streamline usage.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@Copilot Copilot AI review requested due to automatic review settings June 21, 2025 13:34
Copy link

netlify bot commented Jun 21, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 4b39718
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/6856b4e1717bf20008c1f848
😎 Deploy Preview https://deploy-preview-5463--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 75 (🔴 down 2 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors dev.setupMiddlewares to accept a single function or an array of functions, removing the need for redundant array syntax.

  • Change type signature to SetupMiddlewaresFn | SetupMiddlewaresFn[]
  • Update core middleware application to use castArray
  • Refresh documentation and tests to use the new function-only syntax

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
website/docs/{zh,en}/guide/basic/server.mdx Updated examples to drop the array wrapper around middleware fn
website/docs/{zh,en}/config/dev/setup-middlewares.mdx Adjusted type definitions and examples for union syntax
packages/core/src/types/config.ts Changed setupMiddlewares type to accept fn or fn array
packages/core/src/server/devMiddlewares.ts Added castArray import and loop to handle single or array
e2e/cases/server/**/* Simplified test configs to use direct function syntax
Comments suppressed due to low confidence (1)

e2e/cases/server/setup-middlewares/index.test.ts:4

  • Add a test case that passes setupMiddlewares as an array (the old syntax) to verify backward compatibility with the new union type.
test('should apply custom middleware via `setupMiddlewares`', async ({

@chenjiahan chenjiahan merged commit 471d61a into main Jun 22, 2025
12 checks passed
@chenjiahan chenjiahan deleted the setup_middlewares_0621 branch June 22, 2025 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant