Introduction
a node.js application that mocks api based on configuration
Features
-
mock response
configure routers so the api respond with provide json file, for example:
{ "path": "/example", "data": "./data/example.json", "method": "get" }
then a request
GET /example
will get response with content of the file./data/example.json
-
default proxy
for all requests to a path that has not been defined in previous configuration, the api will work as a proxy and redirect the request to a specificed proxy server.
for example: given that
"proxy": "http://localhost:9528"
has been set, and path/api/element/1
has not been mocked, then a requestGET /api/element/1
will be proxied tohttp://localhost:9528/api/element/1
and get response from the proxy server. -
cors allowed for all origins
Usage
npm install
- locate
./src/config/default.json
for configuration - (optional) modify
app.port
to the port you want to host the mock api - (optional) modify
proxy
to the hostname of the proxy server, which will handle unrouted requests - update
routers
for mocks npm start