Changed from axios to fetch.
This commit is contained in:
parent
0047f06386
commit
9a23df34fb
@ -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});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user