#
Proxy 'Any' Website
This guide provides step-by-step instructions for setting up a proxy and using it to access any website you want, regardless of regional restrictions and censorship. FYI, not all websites can be proxied using this method.
- Sign up on https://www.cloudflare.com/ if not already.
- Click on workers tab.
- Choose a subdomain where you would like to see your workers.
- *such as zyx.subdomain.workers.dev
- *here zyx will be replaced by your future worker names.
- *the subdomain will stay same for all future workers.
- After selecting subdomain click on create a service/worker.
- Name your new worker anything you want.
- Click create.
- Click quick edit.
- Click next.
- Delete existing code.
- Paste the following code there.
- Use the instructions provided underneath the code blocks.
- Two sets of code have been provided.
- Try the CODE I first.
- If it doesn't work, try CODE II.
- If both don't work, website can't be proxied using this method.
async function handleRequest(request) {
const url = new URL(request.url)
let response
// Check if the hostname is present in the ORIGINS object
if (url.hostname in ORIGINS) {
const target = ORIGINS[url.hostname]
url.hostname = target
response = await fetch(url.toString(), {
method: request.method,
headers: request.headers
})
} else {
response = await fetch(request)
}
return new HTMLRewriter()
.on('a', new LinkHandler(url))
.on('form', new FormHandler(url))
.on('*', new ElementHandler(url, ORIGINS))
.transform(response)
}
class LinkHandler {
constructor(baseUrl) {
this.baseUrl = baseUrl
}
element(element) {
let href = element.getAttribute('href')
if (href) {
element.setAttribute('href', new URL(href, this.baseUrl).pathname + new URL(href, this
.baseUrl).search)
}
}
}
class FormHandler {
constructor(baseUrl) {
this.baseUrl = baseUrl
}
element(element) {
let action = element.getAttribute('action')
if (action) {
element.setAttribute('action', new URL(action, this.baseUrl).pathname + new URL(action, this
.baseUrl)
.search)
}
}
}
class ElementHandler {
constructor(url, ORIGINS) {
this.url = url
this.ORIGINS = ORIGINS
}
element(element) {
if (element.tagName === 'script' || element.tagName === 'link' || element.tagName === 'img') {
let src = element.getAttribute('src') || element.getAttribute('href')
if (src) {
let srcUrl = new URL(src, this.url)
if (srcUrl.hostname in this.ORIGINS) {
let target = this.ORIGINS[srcUrl.hostname]
srcUrl.hostname = target
}
element.setAttribute(element.tagName === 'script' ? 'src' : 'href', srcUrl.toString())
}
}
}
}
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
const ORIGINS = {
'1337x.subdomain.workers.dev': '1337x.to'
}
async function handleRequest(request) {
const url = new URL(request.url)
if (url.hostname in ORIGINS) {
const target = ORIGINS[url.hostname]
url.hostname = target
return fetch(url.toString(), request)
}
return fetch(request)
}
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
const ORIGINS = {
'1337x.subdomain.workers.dev': '1337x.to'
}
- Replace 1337x with whatever you named your new worker.
- Replace subdomain with whatever you set your subdomain to.
- Replace 1337x.to with the website you want to be proxied.
- Don't enter https://1337x.to/
- Only 1337x.to
BOOM, you can access your proxied website at 1337x.subdomain.workers.dev
Enjoy and cheers!