{"id":13582879,"url":"https://github.com/chinesedfan/parrot-mocker-web","last_synced_at":"2025-04-13T05:28:29.990Z","repository":{"id":57319242,"uuid":"86557428","full_name":"chinesedfan/parrot-mocker-web","owner":"chinesedfan","description":"Simple web server to forward received requests to real servers or just mock","archived":false,"fork":false,"pushed_at":"2020-08-21T14:43:43.000Z","size":2795,"stargazers_count":215,"open_issues_count":5,"forks_count":22,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-10T14:46:58.689Z","etag":null,"topics":["koa","mock-server","parrot-mocker","vue2","vuex"],"latest_commit_sha":null,"homepage":"https://parrotmocker.leanapp.cn/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chinesedfan.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-29T08:31:38.000Z","updated_at":"2024-11-06T20:43:53.000Z","dependencies_parsed_at":"2022-08-25T22:42:29.316Z","dependency_job_id":null,"html_url":"https://github.com/chinesedfan/parrot-mocker-web","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinesedfan%2Fparrot-mocker-web","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinesedfan%2Fparrot-mocker-web/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinesedfan%2Fparrot-mocker-web/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinesedfan%2Fparrot-mocker-web/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chinesedfan","download_url":"https://codeload.github.com/chinesedfan/parrot-mocker-web/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248668736,"owners_count":21142732,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["koa","mock-server","parrot-mocker","vue2","vuex"],"created_at":"2024-08-01T15:03:05.680Z","updated_at":"2025-04-13T05:28:29.953Z","avatar_url":"https://github.com/chinesedfan.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# parrot-mocker-web [![npm version](https://badge.fury.io/js/parrot-mocker-web.svg)](https://badge.fury.io/js/parrot-mocker-web) [![Build Status](https://travis-ci.org/chinesedfan/parrot-mocker-web.svg?branch=master)](https://travis-ci.org/chinesedfan/parrot-mocker-web) [![Coverage Status](https://coveralls.io/repos/github/chinesedfan/parrot-mocker-web/badge.svg?branch=master)](https://coveralls.io/github/chinesedfan/parrot-mocker-web?branch=master) [![License](https://img.shields.io/github/license/chinesedfan/parrot-mocker-web.svg)][license]\n\n项目提供一个简单的mock服务器，配合Chrome插件[parrot-mocker](https://github.com/chinesedfan/parrot-mocker)，支持：\n- 转发页面请求(xhr/jsonp/fetch)到真正的web服务器，或者只返回mock数据\n- 列表展示被转发的请求\n- 针对特定请求配置特定mock数据\n\n不支持：\n- cookie敏感的请求，因为插件转发的请求只携带了'页面所在域'的cookie，而不是'请求本身的域'的cookie\n- 相对于页面的请求或本地特有dns的请求，因为此类请求到达mock服务器后，无法解析到真正的host\n- ~~https页面，除非把本项目部署成https~~（已部署到[leancloud][index-lean]和[now.sh][index-now]）\n\n## 如何使用\n\n### 1.准备\n\n安装Chrome插件，[parrot-mocker](https://chrome.google.com/webstore/detail/parrotmocker/hdhamekapmnmceohfdbfelofidflfelm)，使得页面上的请求可以被拦截转发到mock服务器。其它非插件式用法，参考：[如何使用二维码](https://github.com/chinesedfan/parrot-mocker-web/blob/master/doc/zh/how-to-use-qrcode.md)。\n\n\u003cimg src=\"pic/1.install.png\" width=\"80%\" /\u003e\n\n### 2.访问\n\n以项目部署在[leancloud][index-lean]为例，使用前必须先在Chrome中打开[首页][index-lean]。[now.sh][index-now]或其它部署地址类似。\n\n\u003cimg src=\"pic/2.1.index.png\" width=\"80%\" /\u003e\n\n正常访问需要测试的页面，例如：[demo页面](https://chinesedfan.github.io/parrot-mocker/demo.html)，该页面加载完后会分别发送xhr/jsonp/fetch三个请求。\n\n\u003cimg src=\"pic/2.2.demo.png\" width=\"80%\" /\u003e\n\n打开插件输入mock服务器的地址并点击mock按钮，页面会自动刷新。\n\n\u003cimg src=\"pic/2.3.prepare.png\" width=\"80%\" /\u003e\n\n此时会发现页面请求已经被转发到了mock服务器，在[首页](https://parrotmocker.leanapp.cn)上也可以浏览到。如果再访问相同域的其它页面都将具有相同效果，因为插件在cookie中记录了转发相关信息。\n\n\u003cimg src=\"pic/2.4.retransmit.png\" width=\"80%\" /\u003e\n\u003cimg src=\"pic/2.5.list.png\" width=\"80%\" /\u003e\n\n### 3.Mock\n\n选中请求列表中的任意请求，然后点击'Add'按钮，该请求就被添加到mock配置中。\n\n打开[Config页面](https://parrotmocker.leanapp.cn/html/config.html)可以编辑mock数据，记得'Apply'才能让mock数据真正生效。参考：[如何配置](https://github.com/chinesedfan/parrot-mocker-web/blob/master/doc/zh/how-to-config.md)\n\n\u003cimg src=\"pic/3.1.mock.png\" width=\"80%\" /\u003e\n\n刷新原来的测试链接，会发现数据已经被mock。\n\n\u003cimg src=\"pic/3.2.result.png\" width=\"80%\" /\u003e\n\u003cimg src=\"pic/3.3.list.png\" width=\"80%\" /\u003e\n\n### 4.停止\n\n点开插件然后点击红色按钮，页面将恢复原状。\n\n## 本地启动\n\n默认启动在主端口8080，子端口8442/8443。子端口只能通过对应的http/https方式访问，主端口同时支持两种协议。其中https因为是本地自签名的，所以浏览器会发出警告，选择继续访问即可。\n\n```sh\nnode ./server/index.js\n```\n\n或者也可以通过环境变量来更换端口。\n\n```sh\nPORT=8888 HTTP_PORT=9442 HTTPS_PORT=9443 node ./server/index.js\n```\n\n为了使用本地服务，步骤2需要访问和在插件中输入本地地址作为mock server，例如：`https://127.0.0.1:8080`，其它步骤类似。\n\n## 注意\n\n- 为了重定向类请求能被正确处理，请确保服务器能通过你在Chrome插件中输入的mock server域名访问到自身。\n\n## 开源协议\n\n[MIT][license]\n\n## 致谢\n\n* [jsoneditor](https://github.com/josdejong/jsoneditor), json编辑器\n\n[index-lean]: https://parrotmocker.leanapp.cn\n[index-now]: https://parrotmocker.now.sh\n[license]: https://github.com/chinesedfan/parrot-mocker-web/blob/master/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchinesedfan%2Fparrot-mocker-web","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchinesedfan%2Fparrot-mocker-web","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchinesedfan%2Fparrot-mocker-web/lists"}