mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
fix: with-cloudflare-workers example
This commit is contained in:
1 parent
8105db9f20
commit
c3ea9100be
4 files changed
+612
-3575
No files matched your search
@@ -1,25 +1,28 @@
|
||||
import { createClient } from '@supabase/supabase-js'
|
||||
|
||||
// Fill you client credential here.
|
||||
const db = createClient('YOUR_SUPABASE_URL', 'YOUR_SUPABASE_KEY')
|
||||
|
||||
addEventListener('fetch', (event) => {
|
||||
event.respondWith(handleRequest(event.request))
|
||||
})
|
||||
|
||||
async function handleRequest(request) {
|
||||
try {
|
||||
// Uncomment this part to start querying your database using Supabase client.
|
||||
//
|
||||
// const { data, error } = await db
|
||||
// .from("TABLE")
|
||||
// .select("name");
|
||||
// console.log(JSON.stringify(data, null, 2));
|
||||
} catch (error) {
|
||||
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('links').select('*')
|
||||
|
||||
if (error) {
|
||||
console.log(error)
|
||||
return new Response(error.message || error.toString(), {
|
||||
status: 500,
|
||||
})
|
||||
}
|
||||
|
||||
return new Response('Hello worker!', {
|
||||
headers: { 'content-type': 'text/plain' },
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
}
|
||||
+593
-3547
File diff suppressed because it is too large.
Load diff
@@ -7,14 +7,12 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "wrangler dev",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"postinstall": "patch-package"
|
||||
"deploy": "wrangler publish"
|
||||
},
|
||||
"dependencies": {
|
||||
"@supabase/supabase-js": "^1.3.3"
|
||||
"@supabase/supabase-js": "^1.30.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"patch-package": "^6.2.2",
|
||||
"postinstall-postinstall": "^2.1.0"
|
||||
"@cloudflare/wrangler": "^1.19.8"
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
diff --git a/node_modules/cross-fetch/dist/browser-ponyfill.js b/node_modules/cross-fetch/dist/browser-ponyfill.js
|
||||
index 7a795ac..c01e55f 100644
|
||||
--- a/node_modules/cross-fetch/dist/browser-ponyfill.js
|
||||
+++ b/node_modules/cross-fetch/dist/browser-ponyfill.js
|
||||
@@ -544,3 +544,4 @@ exports.Headers = __self__.Headers
|
||||
exports.Request = __self__.Request
|
||||
exports.Response = __self__.Response
|
||||
module.exports = exports
|
||||
+module.exports = fetch
|
||||
\ No newline at end of file
|
||||
Reference in new issue
Block a user