Skip to content

feat: allow onBeforeStartDevServer hook to return post callback#4573

Merged
chenjiahan merged 3 commits intomainfrom
post_server_callback_0216
Feb 17, 2025
Merged

feat: allow onBeforeStartDevServer hook to return post callback#4573
chenjiahan merged 3 commits intomainfrom
post_server_callback_0216

Conversation

@chenjiahan
Copy link
Copy Markdown
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).

@netlify
Copy link
Copy Markdown

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

@netlify
Copy link
Copy Markdown

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.

@netlify
Copy link
Copy Markdown

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.

1 participant