Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
function returning [object Promise]

I'm trying to return the value of the first function, and use as variable on the second function, but it's showing this [object Promise].

addEventListener("fetch", event => {
  event.respondWith(fetchAndStream(event.request))
});

async function handleRequest(request) {
      var uri = request.url.replace(/^https:\/\/.*?\//gi, "/");
      return uri;
}

async function fetchAndStream() {

    uri = handleRequest();
    console.log(uri);
    // Fetch from origin server.
    let response = await fetch('http://blablabla.com/' + uri);

    const responseInit = {
        headers: {
            'Content-Type': 'application/octet-stream',
            'Content-Disposition': 'attachment; filename="file.m3u"',
        }
    };

    // ... and deliver our Response while that's running.
    return new Response(response.body, responseInit)
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are calling your functions incorrectly without arguments. Your handleRequest takes an argument request in your function declaration

async function handleRequest(request) 

In your event listener you are calling the callback with an argument

fetchAndStream(event.request)

But you don't take any arguments here.

async function fetchAndStream() {

    uri = handleRequest();
    console.log(uri);

Since you have used your function handleRequest with async. It returns a promise wrapper which will await the execution, which I have doubts it will complete from there. The wrapper is like a placeholder which will be filled once your promise completes but since you are not calling the functions properly. Hence you are getting the output.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda