banner
 Sayyiku

Sayyiku

Chaos is a ladder
telegram
twitter

利用cloudflare workers 反代蜜柑计划的RSS

image

由于蜜柑RSS的订阅遭到GFW的封锁,大部分部署在国内的自动下载RSS应该都无法连接失效了

1.注册cloudflare#

2.启用Workers#

image image image

const TELEGRAPH_URL = 'https://mikanani.me';
const MY_DOMAIN = 'https://yourdomain.com'

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  const url = new URL(request.url);
  url.host = TELEGRAPH_URL.replace(/^https?:\/\//, '');

  const modifiedRequest = new Request(url.toString(), {
    headers: request.headers,
    method: request.method,
    body: request.body,
    redirect: 'manual'
  });

  const response = await fetch(modifiedRequest);
  const contentType = response.headers.get('Content-Type') || '';

  // 如果内容类型是 RSS,才进行替换操作
  if (contentType.includes('application/xml')) {
    const text = await response.text();
    const replacedText = text.replace(/https?:\/\/mikanani\.me/g, MY_DOMAIN);
    const modifiedResponse = new Response(replacedText, response);

    // 添加允许跨域访问的响应头
    modifiedResponse.headers.set('Access-Control-Allow-Origin', '*');

    return modifiedResponse;
  } else {
    const modifiedResponse = new Response(response.body, response);

    // 添加允许跨域访问的响应头
    modifiedResponse.headers.set('Access-Control-Allow-Origin', '*');

    return modifiedResponse;
  }
}
image

解析设置自定义域名#

因为workers.dev 域名本身也是被墙的因此我们需要更换自己的没被墙的域名

image image

成功示例#

image
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.