{"id":22059627,"url":"https://github.com/gauseen/web-proxy","last_synced_at":"2026-04-12T00:47:16.974Z","repository":{"id":57113055,"uuid":"130493072","full_name":"gauseen/web-proxy","owner":"gauseen","description":"Create http proxy support Hot update","archived":false,"fork":false,"pushed_at":"2018-07-05T02:08:00.000Z","size":41,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-07T09:40:00.226Z","etag":null,"topics":["ajax","cross-domain","js","proxy","website"],"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/gauseen.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}},"created_at":"2018-04-21T16:43:17.000Z","updated_at":"2018-09-17T08:49:59.000Z","dependencies_parsed_at":"2022-08-21T23:10:39.486Z","dependency_job_id":null,"html_url":"https://github.com/gauseen/web-proxy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gauseen%2Fweb-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gauseen%2Fweb-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gauseen%2Fweb-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gauseen%2Fweb-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gauseen","download_url":"https://codeload.github.com/gauseen/web-proxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244124196,"owners_count":20401685,"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":["ajax","cross-domain","js","proxy","website"],"created_at":"2024-11-30T17:30:04.046Z","updated_at":"2026-04-12T00:47:16.938Z","avatar_url":"https://github.com/gauseen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#### 创建本地服务，及服务代理，支持热更新\r\n### Create http proxy support Hot update\r\n\r\n### TODO\r\n\r\n#### 特别针对老型项目设计，没有使用构建工具（ webpack、gulp、grunt etc.）\r\n\r\n\u003e 确保你的 nodejs 版本 \u003e= 8.0.0，\r\n\u003e 解决跨域问题，支持本地开发热更新\r\n\r\n---------------\r\n### 安装（install）\r\n\r\n```bash\r\nyarn add @gauseen/web-proxy -D    # 推荐\r\n# or\r\nnpm i @gauseen/web-proxy -D\r\n```\r\n\r\n### 使用（usage）\r\n\r\n```js\r\n// 首先，在项目根目录创建 server.js 文件\r\n```\r\n\r\n```js\r\n// 例子：\r\n// server.js\r\n\r\nconst path = require('path')\r\nconst server = require('@gauseen/web-proxy')\r\n\r\nconst options = {\r\n\twatch: false,\r\n\twatchStatic: path.join(__dirname, './demo/'),\r\n\tserverStatic: path.join(__dirname, './'),\r\n\tport: 8008,\r\n\tproxyTable: {\r\n\t\t'/api': { target: 'http://doman.com/', }\r\n\t\t/* '/apiFlag': {\r\n\t\t\ttarget: 'http://doman.com/',\r\n\t\t\tpathRewrite: {\r\n\t\t\t\t// ^/old-path' : '/new-path\r\n\t\t\t\t// 下面配置是将，/apiFlag 开头的请求，重写为 /newFlag，也可为 '' (空)\r\n\t\t\t\t'^/apiFlag': '/newFlag',\r\n\t\t\t}\r\n\t\t} */\r\n\t},\r\n\tnotify: true,\r\n\tignores: ['js'],\r\n\tcallback: function () {\r\n\t\tconsole.log('Server run success ...')\r\n\t},\r\n}\r\n\r\nserver(options)\r\n```\r\n\r\n### options 参数说明：\r\n| 参数 | 说明 | 类型 | 默认 | 是否必选 | 可选项 |\r\n|------|-------|---------|-------|--------|--------|\r\n| `watch` | 是否开启热更新 | `Boolean` | `false` | 是 | - |\r\n| `watchStatic` | 热更新目录 | `String` | | 是 | - |\r\n| `serverStatic` | 静态服务目录 | `String` | | 是 | - |\r\n| `proxyTable` | 要代理的 `doman` | `Object` | | 是 | - |\r\n| `port` | 端口 | `Number` | `8008` | 否 | - |\r\n| `notify` | 是否在浏览器端显示通知 | `Boolean` | `false` | 否 | - |\r\n| `ignores` | 忽略 `watch` 文件格式 | `Array` | - | 否 | `[css, html, js]` |\r\n| `callback` | 服务启动成功回调 | `Function` | - | 否 | - |\r\n\r\n### 启动服务\r\n\r\n```bash\r\nnode server.js\r\n# 或\r\n# 自己配置 npm scripts 运行\r\n\r\n# 更改 server.js 文件后要重启服务，更改才生效\r\n```\r\n### 浏览器运行\r\n`localhost: \u003cport\u003e/`\r\n\r\n\r\n### 注：\r\n```bash\r\nproxyTable 是个对象，\r\n\r\n键 为: 请求 URL 的统一标识字段，如请求接口：http://doman/api/back/login，那么 api 就是它的标识字段\r\n\r\n值 为: {\r\n\ttarget: 要代理的（域名或IP） doman, # (必填)\r\n\tpathRewrite: { '^/oldFlag': '/newFlag', } # (非必填)\r\n}\r\n\r\npathRewrite 字段作用是防止后端接口比较混乱，没有统一的标识符，\r\n这时前端在本地开发时，可以自己添加一个统一标识符，并使用 pathRewrite 的功能，再让这个字段设置为空字符，这样就可以请求到服务端本来的 URL\r\n```\r\n\r\n#### 如果好用还望给个 Star， 您的 Star 是我最大的动力，谢谢！\r\n\r\n[GitHub 地址](https://github.com/gauseen/web-proxy)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgauseen%2Fweb-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgauseen%2Fweb-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgauseen%2Fweb-proxy/lists"}