请问GitHub Copilot免科学访问,需要修改/代理哪几个url地址?

正版购买的,但朋友没有梯子使用补全和chat都不稳定,我用CF Worker+域名代理了github api网址,想让免翻墙使用github copilot chat和补全。

参考了很多项目更换url路径都没有成功,有点分不清楚这几个url是有什么区别的。
有大佬指明一下具体应该更换哪几个url连接吗?主要是idea中使用,谢谢。

vscode:
{
    "github.copilot.advanced": {
        "authProvider": "github-enterprise",
        "debug.overrideProxyUrl": "",
        "debug.overrideCAPIUrl": "",
        "debug.overrideChatEngine": "gpt-4",
    },
    "github-enterprise.uri": ",
}

idea配置系统环境变量:
GH_COPILOT_OVERRIDE_PROXY_URL=
GH_COPILOT_OVERRIDE_CAPI_URL=

4 Likes

改hosts就可以了

1 Like

可以直接使用vscode的http_proxy进行代理,连你的服务器

1 Like

这么麻烦吗

直接改hosts不行?

1 Like
// 监听 fetch 事件
addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request, event));
});

// 处理请求的主函数
async function handleRequest(request, event) {

  
  //可以定义一个map,通过请求后缀来取出对应的url去请求
  //例如: 请求到cf的url: https://cf.com/a -> 截取到a  从['a':'https://a.com','b':'https://b.com'] 取出a对应的https://a.com
  //然后将原始请求的 URL 替换为 实际 的 URL


  // 初始化 fetch 请求配置
  const fetchOptions = {
      method: request.method,
      headers: new Headers(request.headers)
  };

  // 删除一些不必要的头信息
  fetchOptions.headers.delete('cf-connecting-ip');
  fetchOptions.headers.delete('cf-ipcountry');
  fetchOptions.headers.delete('cf-ray');
  fetchOptions.headers.delete('cf-visitor');

  // 如果请求是 POST 或 PUT,则读取并设置请求体
  if (['POST', 'PUT'].includes(request.method)) {
      const requestBody = await request.text();
      fetchOptions.body = requestBody;

      // 记录请求体(可选)
      // console.log(`Request body: ${requestBody}`);
  }

  try {
      // 转发请求到新的 URL
      const response = await fetch(newUrl, fetchOptions);

      // 读取响应体
      const responseBody = await response.text();

      // 处理响应头
      const responseHeaders = new Headers(response.headers);
      responseHeaders.delete('some-unwanted-header'); // 删除不必要的响应头
      responseHeaders.set('Access-Control-Allow-Origin', '*'); // 设置CORS头信息

      // 返回修改后的响应
      return new Response(responseBody, {
          status: response.status,
          statusText: response.statusText,
          headers: responseHeaders,
      });
  } catch (error) {
      // 错误处理
      return new Response(`Error fetching the URL: ${error.message}`, { status: 500 });
  }
}

需要你自己完成的逻辑部分:
//可以定义一个map,通过请求后缀来取出对应的url去请求
//例如: 请求到cf的url: https://cf.com/a → 截取到a 从[‘a’:‘https://a.com’,‘b’:‘https://b.com’] 取出a对应的https://a.com
//然后将原始请求的 URL 替换为 实际 的 URL

这套代码适合绝大部分的转发.比如github的web,tg的请求.youtube的web等等.你可以试试看看能不能转发copliot的

1 Like