kiwi-mock
v1.0.2
Published
基于devServer和mockjs完成接口模拟以及转发
Downloads
3
Readme
kiwi-mock
// devServer配置
const kiwiMock = require('kiwi-mock/mock')
before(app) {
kiwiMock(app)
app.listen(8080, () => {
console.info(`mock服务启动成功: http://localhost:8080`)
})
}
// mock.config.js
const path = require('path');
const fs = require('fs');
const mock = {};
function walk(dirPath) {
fs.readdirSync(dirPath)
.forEach(function (file) {
if (fs.statSync(dirPath + '/' + file).isDirectory()) {
walk(dirPath + '/' + file)
} else if (path.extname(file) === '.js') {
Object.assign(mock, require(dirPath + '/' + file));
}
});
}
walk(path.join(__dirname + '/mock'))
module.exports = {
proxy: {
// 优先级最高,若开启全局配置,mock本地数据失效,全部启用代理
enable: false,
path: '/cssp', // path
// 详见http-proxy-middleware(https://github.com/chimurai/http-proxy-middleware#options)
options: {
target: 'http://localhost:8080',
}
},
mock
};
// ./mock/xxxxxx.js
module.exports = {
'POST /cssp/system/menu/**': 'http://test.kiwi-mock.com',
'GET /cssp/system/menu/**': 'http://test.kiwi-mock.com',
'POST /cssp/index/target/item/*': 'http://test.kiwi-mock.com',
'GET /cssp/index/assess/product/question/*': 'http://test.kiwi-mock.com',
'POST /cssp/**/*': 'http://test.kiwi-mock.com',
'GET /cssp/**/*': 'http://test.kiwi-mock.com'
}