Skip to content

Instantly share code, notes, and snippets.

@BruceWind
Last active January 8, 2024 04:13
Show Gist options
  • Save BruceWind/0bb1894dd7b12607971f75e25d006104 to your computer and use it in GitHub Desktop.
Save BruceWind/0bb1894dd7b12607971f75e25d006104 to your computer and use it in GitHub Desktop.
For Chinese developers, there is a nice way to subscribe your proxy nodes on Cloudlfare.

Subscribing Nodes from Cloudflare Worker to Bypass GFW for Chinese Developers

This document aims to introduce a method for Chinese developers to bypass the GFW by subscribing proxy nodes on Cloudflare Worker.

The GFW is a network firewall implemented by the Chinese government that restricts access to certain international websites and services.

Every Chinese developer need proxy nodes to access development resource. When you have many proxy nodes, some of them is copied from friends, or some nodes are shared on the internet.

You want to subscribe them on different device(windows, iOS,Android), at this case, you must know subconverter. You can find many services of it that other guys established. You know that using services belongs to others is unsafe. So it is a good idea to use cloudflare worker to hold proxy nodes for private use.

Prerequisites

Before proceeding, make sure you have the following:

  • A registered Cloudflare account.
  • Having a domain, because you can not use cloudlfare domain to do so.
  • Basic knowledge of Cloudflare Worker and how to create and deploy it.
  • Nodes' URI, whose format like vmess:, vless:, http2:, etc.

How to Use

The steps:

  • Register and configure a Cloudflare account: You will need to have a Cloudflare account to utilize the Cloudflare Worker service.

  • Create a Cloudflare Worker and open code edit pager.

  • The last step is pasting these code below:

const fileContent = 
`vmess://wn4e1LUNGxxxxxxxxx
http2://xxx:xxx@domain:3306#mark
https://xxx:xxx@domain:3306#mark`;

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

async function handleRequest(request) {
  const url = new URL(request.url)
  const plainText = url.searchParams.get('plain')

  let responseContent = fileContent

  if (plainText === 'true') {
    responseContent = fileContent
  } else {
    responseContent = btoa(fileContent)
  }

  const response = new Response(responseContent, {
    headers: {
      'Content-Type': 'text/plain',
    },
  })

  return response
}

In the code above, I simply convert nodes into base64 format, which is sufficient for most of my use cases. I do not require Clash or any other specialized clients.

Once you click the save and deploy button, remember to associate a new domain with this worker. Afterwards, you can open the domain in a web browser to access the response from the nodes.

In other cases, you may want to hide the information, you can try to edit to add some query param like password, which could avoid information leak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment