node-mocker
v1.2.0
Published
A proxy-pass server to mock backend data automatically.
Downloads
5
Readme
Mocker
A proxy-pass server to mock backend data automatically.
Usage
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
: BooleanTry to load responses from cache, and send requests when no cache data is found.
save
: BooleanFetch from remote and save the successful responses to cache directory (
config.dir
).
Backends
Backends should be an array of objects with attributes below:
prefix
: RequiredThe prefix to match URLs that should be by-passed to proxy.
host
: RequiredThe target host of proxy.
backend_prefix
: OptionalIf other than
null
, theprefix
inrequest.url
will be replaced tobackend_prefix
.