{"id":13827317,"url":"https://github.com/hotstu/open-slim-mock","last_synced_at":"2025-06-27T18:37:48.743Z","repository":{"id":73762748,"uuid":"166180888","full_name":"hotstu/open-slim-mock","owner":"hotstu","description":"A lightweight \u0026 flexible nodejs powered web server  for mock testing \u0026 MITM reverse proxy 一款基于nodejs的服务端程序，用于在app的开发调试阶段更好的与后端人员协作，便于前后端分离，快速定位接口问题","archived":false,"fork":false,"pushed_at":"2022-12-07T11:18:54.000Z","size":91,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T15:35:15.775Z","etag":null,"topics":["http-server","mitm","mock","nodejs","proxy","reverse-proxy"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hotstu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-01-17T07:28:41.000Z","updated_at":"2022-02-25T02:01:28.000Z","dependencies_parsed_at":"2024-01-07T22:50:25.422Z","dependency_job_id":"23082382-7233-4908-8e64-3205cc6ed9b0","html_url":"https://github.com/hotstu/open-slim-mock","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/hotstu/open-slim-mock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hotstu%2Fopen-slim-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hotstu%2Fopen-slim-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hotstu%2Fopen-slim-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hotstu%2Fopen-slim-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hotstu","download_url":"https://codeload.github.com/hotstu/open-slim-mock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hotstu%2Fopen-slim-mock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262313581,"owners_count":23292166,"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":["http-server","mitm","mock","nodejs","proxy","reverse-proxy"],"created_at":"2024-08-04T09:01:53.933Z","updated_at":"2025-06-27T18:37:48.701Z","avatar_url":"https://github.com/hotstu.png","language":"JavaScript","funding_links":[],"categories":["\u003ca id=\"42f9e068b6511bcbb47d6b2b273097da\"\u003e\u003c/a\u003e未分类"],"sub_categories":["\u003ca id=\"3bd67ee9f322e2c85854991c85ed6da0\"\u003e\u003c/a\u003e投毒\u0026\u0026Poisoning"],"readme":"# open-slim-mock\n\n\n\n## 基于nodejs的用于开发调试的服务端程序\n\n开发人员在调试app的时候可以启动本地环境的服务器，而不用后端人员协助，便于前后端分离，快速定位接口问题\n\n## 背景\n\n在公司移动端（Android、html5）开发项目中，为了和不同水平的后端开发人员分工合作，我在业余时间用nodejs编写了一个http服务，用于将测试数据运行在本地的web服务中用于app测试，小而精设计思想，使用文本文档作为数据源，可以随时添加新接口，经过一年的使用，提高了我们的开发效率。现在代码经过完全重构，代码更清晰，功能更强大，现在开业开源出来，同时也展示怎么实现一个自己的web框架。\n\n## 特色\n\n  1. ### 架构\n  基于nodejs 标准库的http模块，没有采用其他笨重的web框架，更底层，更灵活。路由模仿Django，采用正则表达式分发请求到各个router再分发到各个Processor进行处理。使用者可以在router中注册自己需要的processor，对各个不同的请求进行处理，例如你要显示一个json，可以直接使用jsonProcessor，将josn的内容作为参数传入，也可以使用fileProcessor，将写有json字符串的文本地址，作为参数传入。\n  \n  2. ### 扩展性\n  Processor是一个lamda表达式，使用者可以使用现有的Processor或者自己实现Processor，无限扩展\n  现有的Processor：\n  *  fileProcessor.js 拷贝文件类容作为文本输出\n  *  jsonProcessor.js 将json自动转换为string再输出\n  *  latencyProcessor.js 模拟网络延时\n  *  proxyProcessor.js 反向代理远程服务器\n  *  staticDirectoryProcessor.js 处理静态文件目录\n  *  staticFileProcessor.js 处理单个静态文件\n  *  stringProcessor.js 直接输出字符串\n  \n  上面的设计将每一个连接的处理交给一个特定的processor，实现了最小的颗粒话，便于我们灵活配置\n  \n  3. ### 反向代理\n   使用nodejs的stream实现，相当于一个MITM代理，可以将来往的数据dump到console输出，快速定位问题，不用再代码中console输出\n\n## 应用\n\n1. clone 项目\n2. 仿照SampleApp创建自己的路由，通常一个接口一个路由\n3. 编辑serverconfig.json，注册自己的路由\n4. 启动本地测试环境\n- `npm run test` 或者 `yarn test`\n\n## changelog\n * 1.0.0 重构开源\n\n\n\n# more\n|Github|简书| 掘金|JCenter | dockerHub|\n| -------------| ------------- |------------- |------------- |------------- |\n| [Github](https://github.com/hotstu)| [简书](https://www.jianshu.com/u/ca2207af2001) | [掘金](https://juejin.im/user/5bee320651882516be2ebbfe) |[JCenter ](https://bintray.com/hglf/maven)      | [dockerHub](https://hub.docker.com/u/hglf)|\n\n\n\n TODO\n \n - [x] better router loader \n - [x] load config from json\n - [ ] a manage panel user interface\n - [ ] websocket based control of server from manage panel\n - [ ] support api snapshot and save to local\n - [ ] database datasource support\n - [ ] handle memory leak when processor promise is not resolve \u0026 reject\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhotstu%2Fopen-slim-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhotstu%2Fopen-slim-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhotstu%2Fopen-slim-mock/lists"}