Skip to content
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

feat: allow onBeforeStartDevServer hook to return post callback #4573

Merged
merged 3 commits into from
Feb 17, 2025

Conversation

chenjiahan
Copy link
Member

Summary

Allow onBeforeStartDevServer hook to return a post callback, the post callback will be called when the default middlewares are registered:

const plugin: RsbuildPlugin = {
  name: 'test-plugin',
  setup(api) {
    api.onBeforeStartDevServer(async ({ server }) => {
      server.middlewares.use((req, res, next) => {
        if (req.url === '/test.html') {
          res.end('Hello, world!');
        } else {
          next();
        }
      });

      // the post callback will be called when the default middlewares are registered
      return () => {
        server.middlewares.use((req, res, next) => {
          if (req.url === '/test2.html') {
            res.end('Hello, world2!');
          } else {
            next();
          }
        });
      };
    });
  },
};

Documentation will be updated later.

Checklist

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

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
tadeokondrak Tadeo Kondrak
Copy link

netlify bot commented Feb 16, 2025

👷 Deploy Preview for rsbuild processing.

Name Link
🔨 Latest commit fb854f1
🔍 Latest deploy log https://app.netlify.com/sites/rsbuild/deploys/67b1e11f8232860008298be3

fix

Verified

This commit was signed with the committer’s verified signature.
tadeokondrak Tadeo Kondrak
fix

Verified

This commit was signed with the committer’s verified signature.
tadeokondrak Tadeo Kondrak
Copy link

netlify bot commented Feb 16, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit fb854f1
🔍 Latest deploy log https://app.netlify.com/sites/rsbuild/deploys/67b1e11f8232860008298be3
😎 Deploy Preview https://deploy-preview-4573--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: 47 (🔴 down 1 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 site configuration.

Copy link

netlify bot commented Feb 16, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 78a213f
🔍 Latest deploy log https://app.netlify.com/sites/rsbuild/deploys/67b1e16a9d3c4d000881f3fd
😎 Deploy Preview https://deploy-preview-4573--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: 43 (🔴 down 5 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 site configuration.

@chenjiahan chenjiahan merged commit 4501182 into main Feb 17, 2025
14 checks passed
@chenjiahan chenjiahan deleted the post_server_callback_0216 branch February 17, 2025 02:26
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.

None yet

1 participant