Changed from axios to fetch.

This commit is contained in:
Michael Mainguy 2023-08-10 12:31:19 -05:00
parent b714ffb025
commit 322d853b12

View File

@ -1,16 +1,16 @@
import axios from 'axios';
interface Env {
VOICE_TOKEN: string;
}
export const onRequest: PagesFunction<Env> = async (context) => {
try {
const response = await axios.post('https://api.assemblyai.com/v2/realtime/token', // use account token to get a temp user token
{expires_in: 3600}, // can set a TTL timer in seconds.
{headers: {authorization: context.env.VOICE_TOKEN}});
const {data} = response;
return new Response(JSON.stringify(data), {status: 200});
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}
});
const response = await res.json();
return new Response(JSON.stringify(response), {status: 200});
} catch (error) {
return new Response(error.message, {status: 500});
}