Rammerhead ships as an npm package so you can embed the proxy directly into an existing Node.js application instead of running it as a standalone server. This approach is useful when you want to mount the proxy on a custom port, share a listener with an Express app, add your own middleware before requests reach the proxy, or bundle a custom front-end alongside the proxy routes.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/binary-person/rammerhead/llms.txt
Use this file to discover all available pages before exploring further.
Install
testcafe-hammerhead, ws, and mime — are bundled.
All exports
Everything exported byrequire('rammerhead') is documented below. You will use RammerheadProxy, RammerheadSessionFileCache, and addStaticFilesToProxy for most embedding scenarios.
| Export | Description |
|---|---|
RammerheadProxy | The core proxy class. Wraps testcafe-hammerhead’s Proxy with session routing, pipeline hooks, and WebSocket support. |
RammerheadLogging | Structured logger with levels disabled, debug, traffic, info, warn, and error. |
RammerheadSession | A single proxy session. Extends hammerhead’s Session with serialization and URL-shuffling. |
RammerheadSessionAbstractStore | Abstract base class for custom session stores. |
RammerheadSessionMemoryStore | In-process session store backed by a Map. Suitable for development and low-traffic deployments. |
RammerheadSessionFileCache | Production session store that keeps active sessions in memory and serializes inactive ones to disk. |
RammerheadJSAbstractCache | Abstract base for JS rewrite caches. |
RammerheadJSFileCache | Disk-backed LRU cache for rewritten JavaScript. Recommended for production. |
RammerheadJSMemCache | In-memory LRU cache for rewritten JavaScript. |
StrShuffler | URL-shuffling utility used by sessions. |
generateId | Generates a random session ID string. |
addStaticFilesToProxy | Registers an entire directory as static GET routes on the proxy. |
URLPath | URL parsing helper used internally by route handlers. |
Minimal working example
The four steps below are all you need to get a working proxy server: create the proxy, create a session store, attach the store, and register the default routes.Create and attach the session store
server.js
attachToProxy assigns the store to proxy.openSessions so that hammerhead can look up sessions by ID on every request.Register routes and pipeline
server.js
setupRoutes registers the /newsession, /editsession, /deletesession, and /sessionexists HTTP endpoints. setupPipeline adds the IP-restriction and header-stripping middleware.Share a port with an existing Express server
PassdontListen: true to prevent RammerheadProxy from calling server.listen() itself. Then forward incoming requests from your existing HTTP server to the proxy’s internal handlers.
express-integration.js
Serve a custom UI with addStaticFilesToProxy
addStaticFilesToProxy reads a directory recursively and registers every file as a static GET route. If the directory contains an index.html, it is also served at the root path /.
The following routes are reserved by hammerhead and will throw if your static directory contains files that would conflict with them:
/hammerhead.js, /rammerhead.js, /task.js, /iframe-task.js, /messaging, /transport-worker.js, /worker-hammerhead.js.Configure RammerheadLogging
RammerheadLogging accepts six log levels in ascending order of severity: disabled, debug, traffic, info, warn, error. Passing logLevel: 'debug' enables all output including per-request traffic logs.
logger.logLevel = 'warn'.
Version history
The package is published as
rammerhead on npm. Recent changes of note:- v1.2.64 — WebSocket errors are caught; HTTP/2 is re-enabled by default.
- v1.2.63 — Added
overrideExternalProxySettingsfor server-level proxy override; updatedtestcafe-hammerheadfrom24.5.18to31.6.2. - v1.2.5 — Replaced
keyv-lru-fileswith a built-in JS cache implementation (RammerheadJSFileCache,RammerheadJSMemCache,RammerheadJSAbstractCache). - v1.2.2 — Introduced disk-cache option for processed JS files, fixing high server memory usage in multi-worker setups.
- v1.2.0 — Added multi-threading support via
sticky-session-custom. - v1.0.4 — Added support for the
DEVELOPMENTenvironment variable and theaddStaticFilesToProxyutility.