Changed from axios to fetch.

This commit is contained in:
Michael Mainguy 2023-08-10 13:21:38 -05:00
parent 0047f06386
commit 9a23df34fb

View File

@ -1,13 +1,18 @@
interface Env {
VOICE_TOKEN: string;
}
export const onRequest: PagesFunction<Env> = 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});