From 9a23df34fb3b158706b156c6a3bb1bbb18ccbeaf Mon Sep 17 00:00:00 2001 From: Michael Mainguy Date: Thu, 10 Aug 2023 13:21:38 -0500 Subject: [PATCH] Changed from axios to fetch. --- functions/api/voice/token.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/functions/api/voice/token.ts b/functions/api/voice/token.ts index fa6c596..500a1d8 100644 --- a/functions/api/voice/token.ts +++ b/functions/api/voice/token.ts @@ -1,13 +1,18 @@ interface Env { VOICE_TOKEN: string; } -export const onRequest: PagesFunction = async (context) => { + +addEventListener('fetch', event => { + event.respondWith(eventHandler(event)); +}); + +async function eventHandler(event) { try { const res = await fetch('https://api.assemblyai.com/v2/realtime/token', { method: 'POST', body: JSON.stringify({expires_in: 3600}), - headers: {authorization: context.env.VOICE_TOKEN} + headers: {authorization: event.context.env.VOICE_TOKEN} }); const response = await res.json(); return new Response(JSON.stringify(response), {status: 200});