Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

98
Views
Trabajador de Cloudflare para redireccionamiento, bucle infinito

 addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)) }) async function handleRequest(request) { const url = new URL(request.url) var pathname = url.pathname.substring(1, url.pathname.length) var response = await fetch('https://eu-central-1.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/1saas-functions-mmlow/service/urlRedirect/incoming_webhook/cloudWorker', { headers: { "Accept": "application/json", 'Content-Type': 'application/json', }, method: 'POST', body: JSON.stringify({identifier: pathname}), }) const result = await response.json(); if(response.destination) { return Response.redirect(response.destination, 302); } else { return Response.redirect("https://1saas.co", 302); } }

Quiero redirigir al usuario a la URL de destino de respuesta, pero redirige al usuario a menudo, por lo que falla. Creo que el detector de eventos de búsqueda se activa al obtener datos de mongo, pero no puedo encontrar otra forma de hacerlo enlace de ejemplo: http://lyl.ai/6j6P6Zwr

 addEventListener('fetch', event => { try{event.respondWith(handleRequest(event.request))} catch(e){console.log(e)} }) async function handleRequest(request){ try{ const url = new URL(request.url) var pathname = url.pathname.substring(1, url.pathname.length) /*var response = await fetch('https://eu-central-1.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/1saas-functions-mmlow/service/urlRedirect/incoming_webhook/cloudWorker', { headers: { "Accept": "application/json", 'Content-Type': 'application/json', }, method: 'POST', body: JSON.stringify({identifier: pathname}), })*/ if(true){ return Response.redirect("https://1saas.co", 302); } else { return Response.redirect("https://1saas.co", 302); } }catch(e) {console.log(e.message)} }
el segundo fragmento es el estado actual, pero aún se redirige muchas veces al destino, por lo que la redirección falla

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que el problema restante es que las últimas dos líneas usan response.destination en lugar de result.destination . Creé un nuevo trabajador con lo siguiente, y pude probar con éxito sin ruta, y con su ruta de 6j6P6Zwr :

 addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)) }) async function handleRequest(request) { const url = new URL(request.url) var pathname = url.pathname.substring(1, url.pathname.length) var response = await fetch('https://eu-central-1.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/1saas-functions-mmlow/service/urlRedirect/incoming_webhook/cloudWorker', { headers: { "Accept": "application/json", 'Content-Type': 'application/json', }, method: 'POST', body: JSON.stringify({identifier: pathname}), }) const result = await response.json(); if(result.destination) { return Response.redirect(result.destination, 302); } else { return Response.redirect("https://1saas.co", 302); } }

Intente darle una oportunidad, tal vez en un nuevo trabajador / URL para evitar posibles problemas de almacenamiento en caché.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!