Overview
The Express middleware automatically injects the Wormkey overlay script into HTML responses from your Express application.Installation
Usage
Basic Setup
API Reference
wormkeyOverlayMiddleware(options: ExpressOverlayOptions)
Creates Express middleware that injects the Wormkey overlay script into HTML responses.
Configuration options for the middleware
The URL of the Wormkey overlay script. This is typically provided in the CLI output when you start a wormhole.
Returns
An Express middleware function that intercepts and modifies HTML responses.Behavior
HTML Detection
The middleware only modifies responses that:- Are strings
- Have
Content-Type: text/html - Don’t already include the overlay script (checked via
data-wormkey-overlay="1")
Injection Logic
The script tag is injected:- Before
</head>if the closing head tag exists - At the beginning of the body if no
</head>tag is found
Injected Script Tag
data-wormkey-overlay="1" attribute prevents duplicate injections.
TypeScript Types
ExpressOverlayOptions
Example with Environment Variable
Notes
- The middleware intercepts the
res.send()method to inject the script - Only HTML responses are modified (other content types pass through unchanged)
- The middleware checks for existing script tags to prevent duplicates
- Works with any Express-compatible framework