bouncy is a low-level Node.js library that provides HTTP proxy and routing capabilities by wrapping `net.Server`. It allows programmatic redirection of raw HTTP traffic based on request headers (like `Host`), paths, or methods. Developers define routing logic within a callback function, gaining fine-grained control over request and response streams for tasks like load balancing or host-based multiplexing. Version `3.2.2` was published in October 2014, and the project shows no significant activity since then, indicating it is abandoned. It differs from higher-level HTTP frameworks by operating directly with Node.js's `net` and `tls` modules, offering a more primitive, stream-oriented approach to proxying.
npm install bouncyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `bouncy` to create a host-based HTTP router. It sets up two backend servers on ports 8001 and 8002, and a `bouncy` proxy on port 8000. Requests are routed to different backends based on the `Host` header, or handled directly by the proxy, showing basic routing and direct response capabilities.
Consider migrating to a actively maintained proxy library like `http-proxy`, `node-http-proxy`, or `express-http-proxy` for modern Node.js applications.
Ensure `opts.key`, `opts.cert`, and `opts.SNICallback` (if needed) are correctly supplied to the `bouncy` constructor according to the Node.js `tls` module documentation. Test with tools like `openssl s_client` or `curl -v` to diagnose SSL/TLS handshake issues.
Always declare the callback function with three arguments, `function (req, res, bounce)`, if you intend to interact with the HTTP response object (e.g., `res.statusCode = 404; res.end('Not Found');`).Be aware that `bouncy` provides a foundational proxy mechanism. Integrate `bouncy` within a larger application structure or use it for simpler, dedicated proxy tasks. For complex API gateways or advanced routing, consider full-featured proxy solutions or web frameworks with built-in proxy capabilities.
Ensure your project is configured for CommonJS, or use `const bouncy = require('bouncy');` in a CommonJS module. If you must use ESM, consider a dynamic `import('bouncy')` after `require` is globally defined, or use a bundler that handles CJS-to-ESM conversion.Verify that `opts.key` and `opts.cert` point to valid SSL certificate and private key files. For self-signed certificates in development, you might need to use `NODE_TLS_REJECT_UNAUTHORIZED=0` (not for production) or configure your client to trust the self-signed certificate.
Ensure that the port argument passed to `bounce()` or `server.listen()` is a valid integer between 1 and 65535. For example, `bounce(8001);` not `bounce('8001');` (though `bouncy`'s sugar syntax might handle string ports, it's best practice to use numbers).No dependency data recorded yet.