Skip to content

Support Node.js style custom handlers for service bindings and outbound services#9376

Merged
jamesopstad merged 4 commits intomainfrom
james/node-custom-services
May 27, 2025
Merged

Support Node.js style custom handlers for service bindings and outbound services#9376
jamesopstad merged 4 commits intomainfrom
james/node-custom-services

Conversation

@jamesopstad
Copy link
Contributor

@jamesopstad jamesopstad commented May 27, 2025

Fixes #000.

Adds support for Node.js style custom handlers for service bindings and outbound services. This makes it easier to integrate Miniflare with existing Node.js middleware and libraries as req and res objects can be used directly.

new Miniflare({
	serviceBindings: {
		CUSTOM: {
			node: (req, res) => {
				res.end(`Hello world`);
			},
		},
	},
});

Note: I initially tried implementing this with Claude but the code it produced was quite hacky and confusing so I removed it and started again.


  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because:
  • Wrangler / Vite E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s): updated README
    • Documentation not necessary because: updated README
  • Wrangler V3 Backport
    • TODO (before merge)
    • Wrangler PR:
    • Not necessary because: not a Wrangler feature

@jamesopstad jamesopstad requested a review from a team as a code owner May 27, 2025 13:40
@changeset-bot
Copy link

changeset-bot bot commented May 27, 2025

🦋 Changeset detected

Latest commit: 74a9f8e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
miniflare Minor
@cloudflare/pages-shared Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk May 27, 2025
@jamesopstad jamesopstad added the e2e Run wrangler + vite-plugin e2e tests on a PR label May 27, 2025
@github-actions
Copy link
Contributor

github-actions bot commented May 27, 2025

A Wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15279528575/npm-package-wrangler-9376
Prereleases for other packages:

cloudflare-workers-bindings-extension:

wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15279528575/npm-package-cloudflare-workers-bindings-extension-9376 -O ./cloudflare-workers-bindings-extension.0.0.0-v4403a259e.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v4403a259e.vsix

create-cloudflare:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15279528575/npm-package-create-cloudflare-9376 --no-auto-update

@cloudflare/kv-asset-handler:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15279528575/npm-package-cloudflare-kv-asset-handler-9376

miniflare:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15279528575/npm-package-miniflare-9376

@cloudflare/pages-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15279528575/npm-package-cloudflare-pages-shared-9376

@cloudflare/unenv-preset:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15279528575/npm-package-cloudflare-unenv-preset-9376

@cloudflare/vite-plugin:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15279528575/npm-package-cloudflare-vite-plugin-9376

@cloudflare/vitest-pool-workers:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15279528575/npm-package-cloudflare-vitest-pool-workers-9376

@cloudflare/workers-editor-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15279528575/npm-package-cloudflare-workers-editor-shared-9376

@cloudflare/workers-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15279528575/npm-package-cloudflare-workers-shared-9376

@cloudflare/workflows-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15279528575/npm-package-cloudflare-workflows-shared-9376

Note that these links will no longer work once the GitHub Actions artifact expires.

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk May 27, 2025
@jamesopstad jamesopstad added this pull request to the merge queue May 27, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 27, 2025
@jamesopstad jamesopstad force-pushed the james/node-custom-services branch from 0fb39f2 to 74a9f8e Compare May 27, 2025 15:34
@jamesopstad jamesopstad added this pull request to the merge queue May 27, 2025
Merged via the queue into main with commit fdae3f7 May 27, 2025
18 checks passed
@jamesopstad jamesopstad deleted the james/node-custom-services branch May 27, 2025 16:43
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e Run wrangler + vite-plugin e2e tests on a PR

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants