-
Notifications
You must be signed in to change notification settings - Fork 0
node
Eugene Lazutkin edited this page Jul 5, 2026
·
2 revisions
toNodeHandler(handler, options?) adapts the bundler core to the callback world: it returns (req, res, next?) — duck-typed, so it serves bare node:http and Express alike (Express req/res are IncomingMessage/ServerResponse supersets; the module imports no framework).
import {createServer} from 'node:http';
import {createBundler} from 'double-meh-bundler';
import {toNodeHandler} from 'double-meh-bundler/node.js';
const bundle = toNodeHandler(createBundler({isUrlAcceptable: url => url.startsWith('/api/')}));
createServer((req, res) =>
req.url.startsWith('/bundle') ? bundle(req, res) : fallthrough(req, res)
).listen(3000);Express mounts it directly:
app.put('/bundle', toNodeHandler(createBundler({isUrlAcceptable})));| Option | Default | Meaning |
|---|---|---|
compress |
true |
gzip the envelope when the client's Accept-Encoding allows. Bare node:http has no compression-middleware idiom, and the compressed envelope is the bundle's whole payoff — so the adapter owns it. Turn it off when a reverse proxy or middleware compresses for you. |
With a next function supplied (Express style), errors are forwarded to next(error). Without one, the adapter answers 500 application/problem+json itself.
See also: Koa adapter, Bundler core.
Start
API
Protocol
Project