How to proxy cdn.discordapp.com

I am Chinese, you know, I cannot directly visit discordapp, so I try to use workers as a proxy.
code like this:

but got 403 This content is no longer available.

how to fix it? or workers do not support proxy images?

Summary

url like this https://mjproxy.lehug.workers.dev/mj/attachments/1134031746829144104/1165850031564263505/levirlaventno_id6601093218278400_a_bird_with_windcheater_9b239d5c-7ac6-4f74-bebc-115d5061d10d.png

export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);

  const targetPath = url.pathname.replace("/mj/", "/");
  const targetUrl = 'https://cdn.discordapp.com' + targetPath;

  console.log(targetUrl);
    // Copy headers from the original request, but remove any CF headers
  let newHeaders = new Headers();
  for (let pair of request.headers.entries()) {
    if (!pair[0].startsWith('cf-') && !pair[0].startsWith(':')) {
      newHeaders.append(pair[0], pair[1]);
    }
  }

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

  const response = await fetch(modifiedRequest);

  console.log(response);
  return response;

  // return fetch(targetUrl);
},

};

I want to proxy [Preformatted text](http://cdn.discordapp.com)with images

Welcome to the Cloudflare Community!

Workers do support proxying images, as well as any other type of request.

The issue here is - Discord specifically blocked Workers from doing this due to abuse.

Cloudflare Workers make no attempt at hiding themselves, in fact, more of the opposite. Any fetch request outgoing from a Worker sets the CF-Worker header, and that cannot be overriden. As such, Discord simply blocks that. Only Ephemeral Media (like from Slash Commands) and Profile Pictures can be accessed via Workers.

3 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.