https://github.com/gera2ld/node-mocker
DEPRECATED
https://github.com/gera2ld/node-mocker
Last synced: 6 months ago
JSON representation
DEPRECATED
- Host: GitHub
- URL: https://github.com/gera2ld/node-mocker
- Owner: gera2ld
- Created: 2015-12-30T04:42:07.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-28T06:55:52.000Z (almost 10 years ago)
- Last Synced: 2025-08-09T12:15:05.760Z (12 months ago)
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Mocker
===



A proxy-pass server to mock backend data automatically.
Usage
---
``` javascript
const koa = require('koa');
const mocker = require('node-mocker');
const app = koa();
app.use(mocker({
dir: 'mock-data',
mode: false, // false | {save: false, mock: false}
backends: [{
prefix: '/api',
backend_prefix: '/awesome',
host: 'http://awesome.backend.com',
}],
}));
```
### Modes
`config.mode` is either `false` or an object with attributes below:
* `mock`: Boolean
Try to load responses from cache, and send requests when no cache data is found.
* `save`: Boolean
Fetch from remote and save the successful responses to cache directory (`config.dir`).
### Backends
Backends should be an array of objects with attributes below:
* `prefix`: Required
The prefix to match URLs that should be by-passed to proxy.
* `host`: Required
The target host of proxy.
* `backend_prefix`: Optional
If other than `null`, the `prefix` in `request.url` will be replaced to `backend_prefix`.