A simple, zero-dependency http test server, mirroring any http/https request for testing purpose.
Alternatives:
- mirror any http request using JSON response
- (self-signed) https
- plain nodejs, zero (npm) dependencies (except for dev/testing)
- tested with header size up to 32kb
- log http requests
PORT
Default listen port is 8888. The port can be changed by setting the env variablePORT
to another value.USE_TLS
SetUSE_TLS
to any arbitrary value to enable https (tls/ssl encryption).
$ curl http://localhost:8888/foobar
{"method":"GET","url":"/foobar","path":"/foobar","sentHeaders":{"host":"localhost:8888","user-agent":"curl/7.79.1","accept":"*/*"},"sentRawHeaders":["Host","localhost:8888","User-Agent","curl/7.79.1","Accept","*/*"],"body":""}
$ curl -s -H "x-mock-counter: a" http://localhost:8888 | jq .counter
1
$ curl -s -H "x-mock-counter: a" http://localhost:8888 | jq .counter
2
$ curl -s -H "x-mock-counter: b" http://localhost:8888 | jq .counter
1
$ curl -H "x-mock-delay: 2000" http://localhost:8888
# sleep for 2000ms ...
Returns status code.
$ curl -H "x-mock-status: 404" http://localhost:8888
Returns the passed value.
$ curl -s -H "x-mock-body: hello-world" http://localhost:8888 | jq .body
"hello-world"
Make it pass npm test
and then send your pull-request ;-)
See LICENSE.