{"id":21708550,"url":"https://github.com/ufologist/dev-serv","last_synced_at":"2026-04-17T15:07:16.421Z","repository":{"id":136686662,"uuid":"83405533","full_name":"ufologist/dev-serv","owner":"ufologist","description":"开发时使用的专属服务器","archived":false,"fork":false,"pushed_at":"2017-03-07T02:27:23.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-20T17:41:23.647Z","etag":null,"topics":["dev-server","live-reload","mock-server","proxy-server","static-server"],"latest_commit_sha":null,"homepage":null,"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/ufologist.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-02-28T07:57:40.000Z","updated_at":"2017-07-14T16:14:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"db93578c-3a96-4235-af3e-51dc17c93313","html_url":"https://github.com/ufologist/dev-serv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ufologist/dev-serv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufologist%2Fdev-serv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufologist%2Fdev-serv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufologist%2Fdev-serv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufologist%2Fdev-serv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ufologist","download_url":"https://codeload.github.com/ufologist/dev-serv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufologist%2Fdev-serv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31933783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T12:37:54.787Z","status":"ssl_error","status_checked_at":"2026-04-17T12:37:25.095Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["dev-server","live-reload","mock-server","proxy-server","static-server"],"created_at":"2024-11-25T22:27:47.143Z","updated_at":"2026-04-17T15:07:16.404Z","avatar_url":"https://github.com/ufologist.png","language":"JavaScript","readme":"# dev-serv\n\n[![NPM version][npm-image]][npm-url] [![changelog][changelog-image]][changelog-url] [![license][license-image]][license-url]\n\n[npm-image]: https://img.shields.io/npm/v/dev-serv.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/dev-serv\n[license-image]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square\n[license-url]: https://github.com/ufologist/dev-serv/blob/master/LICENSE\n[changelog-image]: https://img.shields.io/badge/CHANGE-LOG-blue.svg?style=flat-square\n[changelog-url]: https://github.com/ufologist/dev-serv/blob/master/CHANGELOG.md\n\n开发时使用的专属服务器. **后来发现通过扩展 puer 能够更好的实现(不需要开两个服务了), 因此已经转投到[puer-proxy](https://github.com/ufologist/puer-proxy)**\n\n* 安装 `dev-serv` 模块\n\n  `npm install dev-serv --save-dev`\n* 增加服务器的配置文件\n  \n  从 `dev-serv/example` 中复制 `_dev-serv.json` 到项目根目录\n\n  配置项说明请参考 [src/dev-serv.js#DEV_SERV_CONFIG](https://github.com/ufologist/dev-serv/blob/master/src/dev-serv.js), 一般仅需要配置 `backend` 参数即可\n* 增加 [puer-mock](https://github.com/ufologist/puer-mock) 接口配置文件\n\n  请参考 [puer-mock 使用文档](https://github.com/ufologist/puer-mock#usage), 复制 `node_modules/puer-mock/example` 下面的所有文件到项目根目录\n* 配置项目的 `package.json` 脚本\n\n  ```json\n  \"scripts\": {\n      \"dev\": \"dev-serv\"\n  }\n  ```\n* 启动服务器\n\n  `npm run dev`\n\n## 开发时使用的服务器需要具备哪些功能\n\n* 静态文件服务器\n* 静态文件修改后浏览器自动刷新\n* Mock API Server\n* 代理后端真实接口(最好 Mock API Server 能够灵活切换到真实接口或者使用 Mock 接口)\n\n即需要集 `static server + mock server + proxy server + live-reload` 于一身\n\n## 实现方案\n\n* 使用 expres 来做静态文件服务器                      -\u003e 正式环境为 nginx\n* 使用 puer-mock 来做 API Server(代理后端的真实接口)  -\u003e 方便切换 mock 接口或者真实接口\n* 使用 http-proxy-middleware 来代理 API Server       -\u003e 正式环境为 nginx 反向代理(或者跨域调用)\n* 使用 puer 中间件来做静态文件修改后浏览器自动刷新      -\u003e 方便开发\n\n即形成下面的结构\n\n* 通过 `:8000` 端口服务静态文件\n* 通过 `:8000/api` 代理在 `:8001` 端口的后端接口\n  * puer-mock 在 `:8001` 端口启动 mock 接口服务\n  * puer-mock 同时代理 `:18520` 端口的后端真实接口, 方便开发时可以随时切换成真实接口\n\n```\n【静态服务器】                                                    【Mock API Server】\nhttp://localhost:8000                                            http://localhost:8001\n┏━━━━━━━━━━━━━━━━━━┓                            ┏━━━━━━━━━━━━━━━━━━┓ \n┃                                 ┃                            ┃                                 ┃\n┃ http://localhost:8000/a.html    ┃                            ┃ Mock API Route Config           ┃\n┃ http://localhost:8000/a.css     ┃                            ┃ http://localhost:8001/user/list ┃\n┃                                 ┃                            ┃                                 ┃\n┃ http://localhost:8000/api       ┃ --http-proxy-middleware--\u003e ┃      Mock API Server(puer-mock) ┃\n┃                                 ┃                            ┗━━━━━━━━━━━━━━━━━━┛\n┃          Static Server(express) ┃                                           \n┃          + Auto Reload          ┃                                           ┃\n┃       (puer-connect-middleware) ┃                                          proxy\n┗━━━━━━━━━━━━━━━━━━┛                                           ┃\n                                                                                v\n\n                                                                 【后端真实接口服务器】\n                                                                 http://localhost:18520\n                                                                 ┏━━━━━━━━━━━━━━━━━━┓\n                                                                 ┃                                 ┃\n                                                                 ┃http://localhost:18520/user/list ┃\n                                                                 ┃                                 ┃\n                                                                 ┃             API Server(Backend) ┃\n                                                                 ┗━━━━━━━━━━━━━━━━━━┛\n```\n\n因此页面上面所有接口的根路径应该为 `:8000/api`\n\n例如:\n\n```javascript\n// 通过代理调用后端接口, 会去请求 puer-mock 的服务\n// 因此实际上请求会发给 http://localhost:8001/user/list\n//\n// 如果 puer-mock 上禁用了这个 mock 接口, 由于 puer-mock 同时代理了后端真实接口\n// 因此实际上请求会发给 http://localhost:18520/user/list\n$.get('http://localhost:8000/api/user/list');\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fufologist%2Fdev-serv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fufologist%2Fdev-serv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fufologist%2Fdev-serv/lists"}