It's a lightweight mock server plugin based on express. No more than 5 minutes of skilled use. It's useful when you develop frontend applications with VS Code github. Document 中文
- Start FMock Server
- Reload FMock Server
- Stop FMock Server
- Config FMock Unit
- Config FMock Server
Install Fmock Server*: Searchfmockin vscode exstention exploer and install it.Config FMock Server: When you open workspace ,this plugin while create a default.fmockfloder and./fmock/setting.jsonin your workspace.Setting.jsonis the server config, you can modify it to adapt your requirements.Config FMock Unit: You can add fmock unit config in./fmockfloder. Fmock unit config file name must like*.fmock.js.Run FMock Server: To start FMock Server. In Explorer of VS Code,click "FMock" in the bottom left corner, then click the start button to run fmock server.When start success, you can use it in yourfrontend projector test it withbrowserorpostman.Reload Fmock Server: When you modify and save settings.json or *.fmock.js files. in Explorer of VS Code in the bottom left corner , then click the reload button to reload config
-
settgin.json:{ name:"servername", port:3000 // default port 3000 } -
*.fmock.js: .fmock.js config like thisfmock(unit| unit[], options?)prop type desc required path string The request path true method string Suported 'all','delete','get','put','post'. Default 'all' false response object This is the default res when there are no filter true filter function If need return different res with different request can use this filter, it has two param and should return a new response. false fmock({ path:"/hello", response:{ code:1, msg:"success", data:{ hello: "fmock" } }, filter:function(request,response){ return response; } }) -
fmock unit.path: FMock Server is based on express 4. The path have all features express.4 path supported. -
fmock unit.filter: Filter is a call back function before server send response. The request param have all props express.4-request supported. -
options: You can set common reponse format, url perfixed with options.
options prop examples
| prop | type | desc | required |
|---|---|---|---|
| fileNameAsPathPerfix | boolean | If set true, current fmock config name will be urlprefix. default is false | false |
| urlPrefix | string | set a editable url prefix | false |
| commonResHandler | object | when you set this prop,response will hanbled by this handle | false |
commonResHandler prop examples
| prop | type | desc | required |
|---|---|---|---|
| handle | string | it must be set when you use commHandler,this value will be prop container fmock unit response | true |
| * | any | you can set anything you common repsone should have | false |
Currently, the extension is in the very initial phase. If you find any bug or have any suggestion/feature request, please submit the issues to the GitHub Repo. Or you can send email to 1104238614@qq.com.