A simple node server to use for testing
274
A simple node server that can run in a docker container that can be used for simple testing.
It console.log all requests received including the body. An optional rules file can be specified to inidcate how any request should be handled. If not provided it responds with Http 200
Two types of rules file is supported
The advantage of using toml is that it support multilines without escaping. It is recommened to use toml format unless you love json and escaping too much :).
["/a/b/c"] # the path
body = '''
{"text": "I love toml"}
'''
headers = {content-type = "application/json"}
responseCode = 200
["a/b/d"] # another path
The rule file is a simple json file that has the following fields.
String.find to see if the request path matches and if it does then the specific entry will be used. No fancy regex at the moment.No validation is done for the rules file. Sample rule file
[
{
"path": "/abc",
"body": "hello world",
"headers": [{"key": "content-type", "value": "text"}, {"key" : "abc", "value": "def"}],
"responseCode" : 200
},
{
"path": "/def",
"body": "hello world 2",
"headers": [{"key": "content-type", "value": "text"}, {"key" : "abc", "value": "def"}],
"responseCode" : 400
}
]
docker build -t "node-mock-server" .
docker pull tabiul/node-mock-server:v1.0.0 (json)
docker pull tabiul/node-mock-server:v2.0.0 (toml)
The server takes the following arguments
docker run -it -p 9080:9080 -v /path/to/rules.json:/rules.json node-mock-server:v1.0.0 -f /rules.json (json)
docker run -it -p 9080:9080 -v /path/to/rules.toml:/rules.toml node-mock-server:v2.0.0 -f /rules.toml (toml)
Content type
Image
Digest
Size
347.5 MB
Last updated
almost 7 years ago
docker pull tabiul/node-mock-server