Hi all,
I`m new here.
So, Ihe been build a worker to redirect url to another hostname with port 81, mas it doesn
t work.
I dont know if I have to configure or I
ve release something on Cloudflare.
Follow my script:
export default {
async fetch(request, env, ctx) {
try {
// Obter a URL da solicitação
const url = new URL(request.url)
// Extrair o caminho após "/nuvemshop" na URL
const newPath = url.pathname.toLowerCase().split('/nuvemshop').slice(1).join('/nuvemshop');
console.log(newPath)
// Construir a URL de redirecionamento com o novo caminho
const redirectURL = `http://linkawscustom.compute.amazonaws.com:81/v1/application/nuvemshop${newPath}`
console.log(redirectURL)
// Construir uma nova solicitação com a URL de redirecionamento
const newRequest = new Request(redirectURL, {
method: request.method,
headers: request.headers,
body: request.body,
})
// Enviar a nova solicitação e aguardar a resposta
const response = await fetch(newRequest)
// Devolver a resposta original
return response
} catch (error) {
console.error('Erro:', error)
// Devolver uma resposta de erro, se necessário
return new Response('Erro interno', { status: 500 })
}
},
}
I'll appreciate your help.