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 { interface Env {
VOICE_TOKEN: string; VOICE_TOKEN: string;
} }
export const onRequest: PagesFunction<Env> = async (context) => {
addEventListener('fetch', event => {
event.respondWith(eventHandler(event));
});
async function eventHandler(event) {
try { try {
const res = await fetch('https://api.assemblyai.com/v2/realtime/token', const res = await fetch('https://api.assemblyai.com/v2/realtime/token',
{ {
method: 'POST', method: 'POST',
body: JSON.stringify({expires_in: 3600}), body: JSON.stringify({expires_in: 3600}),
headers: {authorization: context.env.VOICE_TOKEN} headers: {authorization: event.context.env.VOICE_TOKEN}
}); });
const response = await res.json(); const response = await res.json();
return new Response(JSON.stringify(response), {status: 200}); return new Response(JSON.stringify(response), {status: 200});