annnhan / imitator Goto Github PK
View Code? Open in Web Editor NEWA simple nodejs server that can be mock data, map the static resource, and also be a proxy server.
A simple nodejs server that can be mock data, map the static resource, and also be a proxy server.
ajax
`export function get_monthsales(data, url) {
console.log("元件data:", data);
return dispatch => {
console.log('获取元件数据');
$.ajax({
// url: url + '?currentPage=' + data.currentPage,
url:'http://localhost:8888/api/components',
dataType:'jsonp',
type: 'GET'
}).done(function (data) {
console.log(data);
dispatch({
type: INIT_MONTHSALES,
monthsalesData: data.data.rows,
count: data.data.count
});
});
}
}`
Imitatorfile.js
module.exports = function(imitator) {
imitator({
url: '/api/components', // 匹配的url
result: imitator.jsonp({
"status": 0,
"data": {
"count": 16,
"rows": [
{
"id": 1,
"manufacturer_part_number": "manufacturer_part_number",
"supplier_part_number": "supplier_part_number",
"rohs": "rohs",
"description": "description",
"category": "category",
"stock": "stock",
"pricing": "pricing",
"packaging": "packaging",
"Component_link": "Component_link",
"component_link_description": "component_link_description",
"library_ref": "library_ref",
"extend_info_id": 1,
"created_at": "2016-11-18T07:31:40.000Z",
"updated_at": "2016-11-18T07:31:40.000Z",
"deleted_at": null,
"table_name_id": null,
"supplier_id": null,
"manufacturer_id": null,
"part_status_id": 1,
"mounting_type_id": null,
"part_status": {
"id": 1,
"name": "part_status",
"created_at": "2016-11-18T07:31:40.000Z",
"updated_at": "2016-11-18T07:31:40.000Z",
"deleted_at": null
}
}
]
}
})
});
}
可以通过配置文件设置session吗?
怎么才能使配置文件支持es6写法
我使用了你的文件读取,但是读取出来的都是二进制流,能不能还原成原始的文件,或者下载Gzip文件之类的?
通过在option.result的第二个参数function(req, res) {}里写能实现jsonp,但总没有配置来得省事。
比如
imitator('/news_list?callback=?', imitator.file('./list.json'));
期待能在配置文件里增加支持。
When imitator is running, my config file was changed, The server is restart or not?
because our api will add and restart immitator by hand myself every times.
示例中用的是大写,实际必须小写,建议增加toLowerCase大小写不敏感
取req值,用req.param.name是取不到的,需要用req.param('name')
Imitatorfile.js 文件真实存在
imitator
[WARN] imitator file not found!
Imitator server listening on port 8888
接口返回:
{"status":404,"message":"Not Found","err":{"status":404}}
这个我在今天早上测试的时候被 Boss 看到了,Boss 对我说不用这么麻烦的,直接在 Node.js 的服务器的 router 文件中直接设置相应的 json 数据返回就可以了。
没定位到bug到哪里。。。 无论怎么post,req.body 一直 是{}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.