Why does the preview of site on Cloudflare worker differs from the browser?

140 views Asked by At

I have a domain A.tk in the Cloudflare, and I have a server that cannot use the port 80 with domain A.top. The only way to visit A.top is A.top:61445, so I try to fetch('A.top:61445') in Cloudflare worker, and change the response when visiting A.tk. Everything is OK in the worker but not in the browser, where is the problem?Is it might cause of ICP?(I haven't get it)

async function handleRequest(request) {
  if(request.url.toString().indexOf('learn')!=-1)
  {
    let path = request.url.replace('.tk/', '.top:61445/')
    path = path[-1]=='/'?path:path+'/'
    let real = fetch(path)
    console.log(real.url)  //why is undefined
    return real
  }
  else
  {
    let path = request.url.replace('.tk/', '.top/')
    return fetch(path)
  }
}
addEventListener('fetch', async event => {
  event.respondWith(handleRequest(event.request))
})
1

There are 1 answers

0
freshzy On BEST ANSWER

Cloudflare doesn't allow such port...