rishav
03/23/2022, 4:34 PMdb
declaration in other parts of the app as well?
import { createClient } from '@supabase/supabase-js'
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const db = createClient(
'YOUR_SUPABASE_URL', // Replace with your project's URL
'YOUR_SUPABASE_KEY', // Replace with your project's anon/service_role key
{
fetch: fetch.bind(globalThis), // Tell Supabase Client to use Cloudflare Workers' global `fetch` API to make requests
}
)
const { data, error } = await db.from('YOUR_TABLE_NAME').select('*')
if (error) {
console.log(error)
return new Response(error.message || error.toString(), {
status: 500,
})
}
return new Response(JSON.stringify(data), {
status: 200,
headers: { 'Content-Type': 'application/json' },
})
}
Needle
03/23/2022, 4:34 PM/title
command!
We have solved your problem?
Click the button below to archive it.xananax
03/23/2022, 4:37 PMNeedle
03/23/2022, 4:37 PMxananax
03/23/2022, 4:38 PMxananax
03/23/2022, 4:39 PMfetch
. You could do away with the client completely, and just use fetch
directlyrishav
03/23/2022, 4:43 PMNeedle
03/23/2022, 4:43 PM