Serve static responses, proxy responses and generate random responses from swagger specs.
npm install --global @ftes/fake-server
(oryarn global add @ftes/fake-server
)fake-server --configDir=<config-dir>
(configDir
parameter is mandatory)
The main idea is to use a configDir
from your app repository (copy ./config
from this repo as a template). You can manage and version the fake responses together with the app you are developing. The fake-server
installation uses this app-specific config to generate responses.
The behaviour of the fake server is fully configurable through the configDir/configuration.js
file. The function it exports is called with the express app
instance, the available middleware
and all command line options.
Use ./config
as a template. Copy it to your app's repository. It must contain a configuration.js
and data
folder. The structure of the data
folder is explained below.
Responses can be manually added as files. Also, proxied responses and swagger-generated ones are stored to this directory.
The file matching a request is expected to be present at config/data/<req.path>/<req.method>.json
.
If a segment of req.path
does not have a matching directory the *
directory at that level is used as fallback (if present).
The responses can be manually added. Also, proxied responses and swagger-generated ones are stored to this directory.
Request | Response |
---|---|
GET books |
/data/books/get.json |
GET books/123 |
/data/books/*/get.json |
POST books |
/data/books/post.json |
GET books/123/chapters |
/data/books/123/chapters/get.json |
You can use the provided middleware in your configuration.js
. This includes: