npm install node-http-mockInstall it:
``js`
npm install node-http-mock -g
And run this command in your termial:
`bash`
mock -t [api host] -p [local port] -c [config file]
You can use config file instead of command line options:
`js`
// mock.config.js
module.exports = {
port: 5000,
verbose: true,
proxy: {
target: 'api host',
changeOrigin: true,
},
mock: {
'/url_a': {},
'/url_b': {},
},
}
Run this command to use the config file:
`bash`
mock -c # default config file mock.config.js
mock -c my.mock.config.js # customize config file
node-http-mock can construct mock data from real HTTP streams.It identify APIs according to request url, request method and query strings.
`bash`
[method] [url] ? [query string]
Use -r option to recording these responses as ordinary JSON files in .mock/:
`bash`
mock -r [directory path]
Press Crtl-C will terminate recording and create index.js tracing the JSON files.After that you can import the index.js into your config file manually:
`js`
module.exports = {
// ...
mock: require('./.mock/index.js'),
}
Run this command to see a list of all available options:
`bash``
mock --help
MIT © BinRui.Guan