changed to simple response.
This commit is contained in:
parent
29e1deafc5
commit
f27e3dd3cd
@ -1,34 +1,11 @@
|
|||||||
interface Env {
|
interface Env {
|
||||||
VOICE_TOKEN: string;
|
VOICE_TOKEN: string;
|
||||||
}
|
}
|
||||||
export const onRequest: PagesFunction<Env> = async (context) => {
|
|
||||||
try {
|
|
||||||
console.log('start');
|
|
||||||
|
|
||||||
async function gatherResponse(response: Response) {
|
const handler: ExportedHandler<Env> = {
|
||||||
const {headers} = response;
|
async fetch(request, context) {
|
||||||
const contentType = headers.get('content-type') || '';
|
console.log(context.VOICE_TOKEN);
|
||||||
if (contentType.includes('application/json')) {
|
return new Response('Hello World 2!');
|
||||||
return await response.text();
|
|
||||||
} else if (contentType.includes('application/text')) {
|
|
||||||
return await response.text();
|
|
||||||
} else if (contentType.includes('text/html')) {
|
|
||||||
return await response.text();
|
|
||||||
} else {
|
|
||||||
return await response.text();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 results = await gatherResponse(res);
|
|
||||||
|
|
||||||
return new Response(results, {status: 200});
|
|
||||||
} catch (error) {
|
|
||||||
return new Response(error.message, {status: 500});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export default handler;
|
||||||
Loading…
Reference in New Issue
Block a user