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 /examplewill 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/1has not been mocked, then a requestGET /api/element/1will be proxied tohttp://localhost:9528/api/element/1and get response from the proxy server.cors allowed for all origins
Usage
npm install- locate
./src/config/default.jsonfor configuration - (optional) modify
app.portto the port you want to host the mock api - (optional) modify
proxyto the hostname of the proxy server, which will handle unrouted requests - update
routersfor mocks npm start