Changed from axios to fetch.
This commit is contained in:
parent
b714ffb025
commit
322d853b12
@ -1,16 +1,16 @@
|
|||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
interface Env {
|
interface Env {
|
||||||
VOICE_TOKEN: string;
|
VOICE_TOKEN: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env> = async (context) => {
|
export const onRequest: PagesFunction<Env> = async (context) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post('https://api.assemblyai.com/v2/realtime/token', // use account token to get a temp user token
|
const res = await fetch('https://api.assemblyai.com/v2/realtime/token',
|
||||||
{expires_in: 3600}, // can set a TTL timer in seconds.
|
{
|
||||||
{headers: {authorization: context.env.VOICE_TOKEN}});
|
method: 'POST',
|
||||||
const {data} = response;
|
body: JSON.stringify({expires_in: 3600}),
|
||||||
return new Response(JSON.stringify(data), {status: 200});
|
headers: {authorization: context.env.VOICE_TOKEN}
|
||||||
|
});
|
||||||
|
const response = await res.json();
|
||||||
|
return new Response(JSON.stringify(response), {status: 200});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return new Response(error.message, {status: 500});
|
return new Response(error.message, {status: 500});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user