http-mockjs-examples
v1.5.2
Published
Examples for http-mocker
Downloads
1
Maintainers
Readme
examples
Examples for http-mocker
use
http-server
Use custom folder named
mymocks
;Configure in package.json instead of configuration file;
Build parameters using mockjs's syntax;
Start the service proxy mode for mock by specify the port and cooperate with http-server,
Configuration method:
{
"scripts": {
"start": "npm run mock | npm run serve",
"serve": "http-server -p 8008 -P http://localhost:8001/",
"mock": "http-mockjs server -p 8001"
},
"httpmock": {
"mockFileName": "mymocks",
"routes": {
"GET /getsomething.do": {
"path": "/get.json"
},
"POST /postsomething.do": {
"path": "/post.json"
}
}
}
}
The content of get.json
is in the style of mockjs:
{
"code":0,
"message":"success",
"result":{
"content":true,
"name":"brizer123",
"domain":"@domain()",
"otherUrl":"@url()",
"desciption":"@cparagraph(1, 3)",
"date":"@date('yyyy-MM-dd')"
}
}
webpack-dev-server
Used with webpack-dev-server
Using a configuration file named
.httpmockrc.json
Using ui tool to improve editing efficiency
webpack configuration script:
const { mocker } = require('http-mockjs')
module.exports = {
devServer:{
port:'8002',
before:(app)=>{
mocker(app)
}
// proxy: {
// '*': 'http://localhost:8000'
// }
}
};
Start command:
{
"scripts": {
"server": "webpack-dev-server",
"mock:ui": "http-mockjs ui"
}
}