{"id":16781096,"url":"https://github.com/2234839/fetch-proxy","last_synced_at":"2025-03-16T20:23:55.677Z","repository":{"id":57234662,"uuid":"365230853","full_name":"2234839/fetch-proxy","owner":"2234839","description":"Avoid cross-domain fetching: use GM.xmlHttpRequest under Grease Monkey and request custom services in other environments for","archived":false,"fork":false,"pushed_at":"2021-05-08T11:11:51.000Z","size":189,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T17:48:45.817Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/2234839.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":"2021-05-07T12:45:53.000Z","updated_at":"2021-05-08T11:21:50.000Z","dependencies_parsed_at":"2022-09-15T04:42:03.133Z","dependency_job_id":null,"html_url":"https://github.com/2234839/fetch-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/2234839%2Ffetch-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2234839%2Ffetch-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2234839%2Ffetch-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2234839%2Ffetch-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2234839","download_url":"https://codeload.github.com/2234839/fetch-proxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243926046,"owners_count":20369918,"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-10-13T07:36:43.118Z","updated_at":"2025-03-16T20:23:55.657Z","avatar_url":"https://github.com/2234839.png","language":"TypeScript","readme":"# fetch-proxy\n\n这个项目分为两部分：fetch-proxy service, fetch-proxy lib\n\n- fetch-proxy service\n  - 提供一个 api 用于代理浏览器发起的请求来避免跨域问题\n- fetch-proxy lib\n  - 和 原生fetch 使用方式一样的函数 (npm package)\n  - 内部主要逻辑如下\n    - if (请求目标和当前网页是同一个域): 直接使用原生 fetch\n    - else (处于油猴脚本的执行环境下): 使用 GM.xmlHttpRequest\n    - else : 通过原生 fetch 调用 fetch-proxy service\n\n## fetch-proxy lib 的使用方式\n\ngithub 网站设置了 CSP 可以去[我的网站尝试下面的脚本](https://shenzilong.cn)\n\n```js\nimport { fetch_proxy } from \"fetch-proxy_lib\";\n\nfetch_proxy(`https://zhihu.com`)\n  .then((response) =\u003e response.text())\n  .then((result) =\u003e console.log(result))\n  .catch((error) =\u003e console.log(\"error\", error));\n```\n\n如果不在油猴环境下使用的话还请自建服务,然后配置 :\n\n```js\nfetch_proxy.config.fetch_proxy_service = \"https://自建服务地址\"\n```\n\n## fetch-proxy service 的使用方式\n\n自用服务，如有同样的需求***请自行另建服务***，请勿白嫖下面的函数计算。(或者[赞助后使用](https://afdian.net/@llej0))\n\n```js\n// fetchproxy.shenzilong.cn 处的云函数位于阿里云，对于被 GFW 的网站访问一般都会超时\nfetch(`${\"https\" || \"http\"}://fetchproxy.shenzilong.cn`, {\n  method: \"POST\",\n  /** 此处参数参见 node-fetch { input: RequestInfo; init?: RequestInit } */\n  body: JSON.stringify({\n    input: \"https://zhihu.com\",\n  }),\n  headers: {\n    \"Content-Type\": \"application/json\",\n  },\n})\n  .then((response) =\u003e response.json())\n  .then((result) =\u003e console.log(result))\n  .catch((error) =\u003e console.log(\"error\", error));\n// 在非知乎站点请求知乎网页会触发跨域\nfetch(`https://zhihu.com`)\n  .then((response) =\u003e response.text())\n  .then((result) =\u003e console.log(result))\n  .catch((error) =\u003e console.log(\"error\", error));\n```\n\n## 开发说明\n\n```bash\npnpm i\npnpm run start\n```\n- https\n  - 在 https 的站点只能获取其他 https 站点的数据、\n  - 部署的时候需要替换掉 ssl 目录下的证书 key 和 pem 文件 (pem 文件是私密的，没有上传到 github)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2234839%2Ffetch-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2234839%2Ffetch-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2234839%2Ffetch-proxy/lists"}