Appearance
Quick start with Supabase Edge Functions
Learn how to send your first request by using a Supabase Edge Function.
Render PDF
ts
import { corsHeaders } from '../_shared/cors.ts';
import getSupabaseClient from '../_shared/supabaseClient.ts';
Deno.serve(async (req) => {
if (req.method === 'OPTIONS') {
return new Response(null, { headers: corsHeaders, status: 204 });
}
try {
// Extracting the authorization header
const authHeader = req.headers.get('Authorization')!;
// Using the Supabase client (if necessary for your use case)
const supabaseClient = getSupabaseClient(authHeader);
// You might need to validate or process the request here
// Retrieving the DOPPIO_API_TOKEN from environment variables
const doppioApiToken = Deno.env.get('DOPPIO_API_TOKEN');
if (!doppioApiToken) {
throw new Error('DOPPIO_API_TOKEN is not set in environment variables');
}
// Your PDF rendering logic
const res = await fetch('https://api.doppio.sh/v1/render/pdf/sync', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${doppioApiToken}`,
},
body: JSON.stringify({
page: {
goto: {
url: "https://www.spacejam.com/1996/",
},
options: {
waitUntil: [
"networkidle0"
]
}
}
}),
});
const data = await res.json();
return new Response(JSON.stringify(data), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 200,
});
} catch (error) {
// Do something :-)
}
});