#Mariadb with cloudflare worker
9 messages · Page 1 of 1 (latest)
On your server running mariadb you have to run cloudflared tunnel. From your worker you can access the mariadb with this library:
https://github.com/cloudflare/worker-template-mysql
I wouldn't recommend that, that's long unmaintained, and starting a new connection to the db for each function run is really inefficient. You'd want to pool the connections or use some http/rest interface between you and the database. Cloudflare does support outbound TCP Connections now, but I don't know of any libraries that have been updated to use it.
nodejs website to cloudflare pages
Cloudflare Pages supports Pages Functions, which run in a similar environment as Workers, as V8 Isolates, not node.js. You only have node.js in the build environment. If your site uses a web framework like Express it won't work on Pages
if he already has a server running I dont see why he shouldnt use cloudflared. For me it worked really well.
But yeah otherwise he'll have to wait for mysql or mysql2 support when workers tcp socket api has been implemented for those libs.
How to use cloudflared with cloudflare pages for connecting my db to the website
It's not the cloudflared part as much as the library, an unmaintained 2 year old fork of a deno mysql driver, and it connects using tcp over websocket (this is a cloudflared limitation), unless you use DOs to pool you're also creating a whole new DB connection each time, not ideal.
I already have one nodejs express working perfectly fine on pages
The only problem is the database connection
I don't like the idea that the lib in not maintained, the website should fetch the data from the database every 10 seconds or less for being fully updated