{"id":21045618,"url":"https://github.com/daixinye/simple-mocxy","last_synced_at":"2025-03-13T22:20:40.147Z","repository":{"id":143923393,"uuid":"110228811","full_name":"daixinye/simple-mocxy","owner":"daixinye","description":"simple hosts switcher \u0026 mock tool","archived":false,"fork":false,"pushed_at":"2018-09-04T13:31:00.000Z","size":87,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-20T17:48:35.245Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/daixinye.png","metadata":{"files":{"readme":"README.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-10T09:29:56.000Z","updated_at":"2018-09-04T13:31:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"e16767e6-5e4c-435f-9ee3-f3746b9fa4d4","html_url":"https://github.com/daixinye/simple-mocxy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daixinye%2Fsimple-mocxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daixinye%2Fsimple-mocxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daixinye%2Fsimple-mocxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daixinye%2Fsimple-mocxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daixinye","download_url":"https://codeload.github.com/daixinye/simple-mocxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243489758,"owners_count":20299001,"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":[],"created_at":"2024-11-19T14:23:23.263Z","updated_at":"2025-03-13T22:20:40.138Z","avatar_url":"https://github.com/daixinye.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-mocxy\n\n一个正向代理，用于切换 Hosts 和数据 Mock。\n\n配合Chrome插件 [SwitchySharp](https://chrome.google.com/webstore/detail/proxy-switchysharp/dpplabbmogkhghncfbfdeeokoefdjegm) 使用更佳。\n\n## 使用\n\n### 配置\n修改 `./data/hosts` 文件，像配置系统Hosts文件一样配置它：\n```\n# 支持单行注释\napi.guapizuzhi.com 127.0.0.1 # 支持行末注释\n\nm.local.guapizuzhi.com\n  ip 127.0.0.1\n  port 8000\n  headers\n    =simple-mocxy true\n    +cookie mock=1;\n\nm.guapizuzhi.com 127.0.0.1\n```\n可以看到，除了映射IP地址之外，我们还可以指定其端口（port），甚至还能修改HTTP 请求的Headers。\n\n需要注意的是，一个域名下面的子配置需要有两个空格的缩进哦。\n\n### 启动\n```shell\n$ npm run start\n\nserver started on 9999\n```\n可以看到代理服务器默认启动在 9999 端口上。\n\n### 配合 SwitchySharp 使用\n在Chrome中安装 [SwitchySharp](https://chrome.google.com/webstore/detail/proxy-switchysharp/dpplabbmogkhghncfbfdeeokoefdjegm) 后，新建情景模式，手动配置HTTP代理（暂不支持HTTPS）为`127.0.0.1:9999`。\n\n接下来Chrome中访问的HTTP站点，都会先通过 simple-mocxy 代理。根据相关配置，代理会将HTTP请求发送到指定的服务器。如果当前网站没有相关配置，代理就会进行透明转发。\n\n## 关于\n\n### simple-moxcy 想尝试解决什么问题？\n\n做前端开发，与后端的联调当然是不可避免的。然而繁杂的本地环境、测试环境、预发环境和线上环境让debug变得异常麻烦。所谓的切换环境，大多数情况下就是切换Hosts。切就切吧...但是切换系统Hosts有一个主要问题是，系统和浏览器通常都会有缓存。而这个缓存给我们带来的直观感受就是，“切换Hosts有延迟”。simple-moxcy 想尝试解决的第一个问题，就是切换Hosts的延迟问题。\n\n除此之外，代码发布到测试环境或预发环境后，我们常常也会面临难以调试的问题。作为一个前端你打开了开发者工具，看到Network下发的数个请求就开始疑惑，是前端没正确处理接口给的数据吗？还是后端给的数据不正确呢？这种情况下，如果能在浏览器端”直接修改接口数据“该有多好。 simple-moxcy 想尝试解决的第二个问题，就是通过配置拦截请求并返回期望的数据，通过一招移花接木，直接就可以进行一个初步的问题定位。\n\n另外，simple-moxcy 还想在系统Hosts配置方式的基础上，加入更多方便的功能，比如把域名指定到某台服务器上的非80端口上、给HTTP Request带上一些Header。这些功能都应该可以通过简单的配置实现。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaixinye%2Fsimple-mocxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaixinye%2Fsimple-mocxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaixinye%2Fsimple-mocxy/lists"}