A Node.js HTTP, HTTPS, or TCP server that:
- logs incoming connections and requests in a readable way
- allows response behaviour to be customized per request (see below)
The second column is a counter of TCP connections, making it easier to reason about which data came in over which connection.
npm ci
-
Create local CA:
mkcert -install
-
Create a certificate:
cd certs mkcert localhost 127.0.0.1
npm start -- [http|https|tcp] [port]
- Mode defaults to
http
- Port defaults to 8080 in
http
mode, 8443 inhttps
mode, or 4444 intcp
mode
HTTPS_PORT=443 docker compose run log-server-https
Request query parameter | Response behaviour |
---|---|
?status={code} |
Set response status code |
?header={name}:{value} |
Add response header. Can be specified multiple times to add multiple headers. |
?delay-headers={duration} |
Delay (in milliseconds) before sending response headers |
?delay-body={duration} |
Delay (in milliseconds) before sending response body |
?body={message} |
Set response body |
?echo |
Send response body equal to request body, chunkwise Note: delay-headers and delay-body are ignored when this is enabled |
Also supports compressed responses (br
, gzip
, deflate
) according to Accept-Encoding
request
header.
e.g.
$ curl -i "http://localhost:8080/?delay-headers=2000&delay-body=1000&status=503&body=Oh%20no!"
Each newline-separated command will be queued and executed in order:
Command | Behaviour |
---|---|
sleep :duration |
Sleep for :duration milliseconds before running the next command |
print :message |
Send :message back to the client |
fin |
Close the connection |
rst |
Forcibly reset the connection |
e.g.
$ printf "print hello\nsleep 2000\nprint world\nsleep 1000\nfin" | nc localhost 4444
Run and restart when files change:
npm run start:watch
Check types:
npm run check
Build to dist/
:
npm run build
Enable HTTPS server tests:
export NODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem"
Run tests:
npm test
Run tests and watch for changes:
npm run test:watch
Run tests, generate coverage report, and exit with non-zero status if coverage is below 100%:
npm run test:coverage