200字
基于边缘函数(阿里云esa)搭建github加速
2025-12-03
2025-12-07
export default {
  async fetch(request) {
    // 获取原始请求的 URL
    const url = new URL(request.url);
    
    // 将目标主机名替换为 github.com
    url.hostname = 'github.com';

    // 构造新的请求对象,保留原请求的方法、头部等信息
    const newRequest = new Request(url.toString(), request);

    try {
      // 发起请求到 github.com
      const response = await fetch(newRequest);

      // 返回响应给客户端
      return response;
    } catch (error) {
      // 错误处理:如果请求失败,返回 500 错误
      return new Response(`Error: ${error.message}`, { status: 500 });
    }
  }
};

评论