-
Hi there, I want to try accessing Supabase db via Cloudflare workers (CFW). However CFW doesnt support XMLHTTPRequest. CFW only support fetch. Digging deeper, it seems that cross-fetch package who called the actual XHR. Is there any recommendation to solve this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
cross-fetch doesn't work in a Cloudflare worker. Looks like faunadb-js also had this issue and they worked around it by allowing users to pass in a custom fetch implementation in the constructor..that seems hacky though. |
Beta Was this translation helpful? Give feedback.
-
Since from what i know it's not possible to connect with tcp in bare Cloudflare Workers, using REST api is CFW way to communicate with database. I think Supabase is using POSTGREST already, i hope we can have option similar with fauna to pass in custom fetch implementation on Subase js client. |
Beta Was this translation helpful? Give feedback.
-
I successfully use I made a repo for this at https://github.com/nascode/cloudflare-workers-supabase-fix I hope this helps people who get stuck with similar problem. |
Beta Was this translation helpful? Give feedback.
-
Dropping in another solution here - as @munster mentioned here, you can use Webpack's // webpack.config.js
module.exports = {
externals: [{ 'cross-fetch': 'fetch' }]
} I made an example project here to show off what that might look like - note that stuff like realtime and auth isn't tested yet, though I'd like to give it a shot soon: https://github.com/signalnerve/supabase-workers-proxy |
Beta Was this translation helpful? Give feedback.
Hi @kiwicopple @inian
I successfully use
patch-package
to patchcross-fetch
so it use globalfetch
instead.I made a repo for this at https://github.com/nascode/cloudflare-workers-supabase-fix
I hope this helps people who get stuck with similar problem.