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)
}