Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
val.forEach(reqData => {
if (reqData.regexp) {
if (!new RegExp(reqData.url).test(req.originalUrl)) {
return false;
}
} else if (req.originalUrl.indexOf(reqData.url) !== 0) {
return false;
}
var apiRes = reqData.res;
data = reqData.mock ? mock.mock(apiRes) : apiRes;
delay = reqData.delay || 0;
// mock.mock(reqData.url,reqData.res);
return true;
})
})
return function(options) {
let result = null
if (respond instanceof Function) {
const { body, type, url } = options
// https://expressjs.com/en/4x/api.html#req
result = respond({
method: type,
body: JSON.parse(body),
query: param2Obj(url)
})
} else {
result = respond
}
return Mock.mock(result)
}
}
/* eslint-disable */
const Mock = require('mockjs');
const trend = function() {
return {
"data": {
configure: '{"title":"趋势图标题Conf","data":[{"namespace":["forDemoNamespace1","forDemoNamespace2"],"product":"noahEE","monitoringType":"instance","metric":"#{metric1}/#{metric2}","statistics":"avg","period":5,"name":"name1","contrast":["1d","1w"]},{"namespace":["forDemoNamespace3","forDemoNamespace4"],"product":"noahEE","monitoringType":"instance","metric":"#{metric3}","statistics":"avg","period":5,"name":"name2","contrast":["1d"]}],"style":{"displayType":"line","unit":"个","nullPointMode":"zero","threshold":99},"link":"http://www.baidu.com","timeType":"relative","time":"before(2h)"}'
},
success: true
};
}
Mock.mock('/mock/mdtrend', 'post', trend);
/* eslint-disable */
const Mock = require('mockjs');
const report = function() {
return {
"data": {
"title": "资源报表conf",
configure : '{"title":"资源报表conf","data":{"namespace":["forDemoNamespace"],"comments":"说明","columns":[{"source":"origin","metric":"#{metric1}-#{metric2}","statistics":"sum","group":"","header":"数据1","alias":"alias3","unit":"%","decimals":3,"threshold":[[0,90,"#ff0000"],[90,95,"#0000ff"],[99,100,"green"]],"timeType":"relative","time":"before(2h)","total":"sum","use":true,"offset":"-1d"},{"source":"origin","metric":"#{metric1}-#{metric2}","statistics":"sum","group":"综合数据","header":"数据1","alias":"alias1","unit":"%","decimals":3,"threshold":[[0,90,"#ff0000"],[90,95,"#0000ff"],[99,100,"green"]],"timeType":"relative","time":"before(2h)","total":null,"use":true,"offset":"-1d"},{"source":"origin","group":"综合数据","header":"数据2","alias":"alias2","metric":"#{metric1}-#{metric2}","unit":"%","decimals":3,"threshold":[[0,90,"#ff0000"],[90,95,"#0000ff"],[99,100,"green"]],"total":null,"use":true},{"source":"column","group":"综合数据","header":"列计算","metric":"#{alias3}+#{alias2}","unit":"","decimals":3,"threshold":[[null,90,"red"],[90,null,"yellow"],[99,100,"green"]],"total":"avg","use":true}]},"link":"http://www.baidu.com"}'
},
success: true
};
}
Mock.mock('/mock/mdreport', 'post', report);
/* eslint-disable */
const Mock = require('mockjs');
const circle = function() {
return {
data: {
configure : '{"title":"仪表图配置path","data":[{"namespace":["forDemoNamespace"],"metric":"#{metric1}/#{metric2}","statistics":"avg"}],"style":{"decimals":4,"unit":"%","max":100,"min":0,"threshold":[[90,99,"yellow"],[0,90,"red"],[99,99.99,"green"]]},"link":"http://www.baidu.com","timeType":"fixed","time":"before(2h)"}',
title: "仪表图配置path"
},
success: true
};
}
Mock.mock('/mock/circle', 'post', circle);
/* eslint-disable */
const Mock = require('mockjs');
const billboard = function() {
return {
data: {
configure : '{"title":"面板配置path","data":[{"namespace":["forDemoNamespace1"],"metric":"#{metric1}/#{metric2}","statistics":"avg","name":"name3","unit":"%","decimals":4},{"namespace":["forDemoNamespace2"],"metric":"#{metric3}","statistics":"avg","name":"name4","unit":"%","decimals":4}],"link":"http://www.baidu.com","timeType":"relative","time":"before(2h)"}',
title: "面板配置path"
},
success: true
};
};
Mock.mock('/mock/billboard', 'post', billboard);
_.each(walk(path.join(__dirname, 'data'), program.data), function(data, index){
var temp = require(data),
relative = path.relative(path.join(__dirname, 'data'), data);//take out the relative
//check whether mock data or not
if( path.extname(relative) === '.js' ){//mock js file
//replace .mock.js with .json
fs.writeFile(path.join(program.data, relative.replace(/(\.mock\.js)/, '.json')), JSON.stringify(Mock.mock(temp), null, '\t'), function(err){
if(err){
return console.log(err);
}
console.log('[', 'exported'.green, '-', 'mock', ']', data);
});
}else{
fs.writeFile(path.join(program.data, relative), JSON.stringify(temp, null, '\t'), function(err){
if(err){
return console.log(err);
}
console.log('[', 'exported'.green, '-', 'copy'.grey, ']', data);
});
}
});
response(req, res) {
console.log('request invoke:' + req.path)
res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond))
}
}
router.get('/get/opencode', function (req, res, next) {
var issue=makeIssue().issue;
var data=mockjs.mock({
'data': [/[1-3]/,/[4-5]/,/[6-7]/,/[8-9]/,/1[0-1]/]
}).data;
res.json({
issue:issue,
data:data
})
});
status2 () {
return Mock.mock({
'data|1': [
'active',
'pending',
'paused',
],
}).data
},
platform () {