New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connecting to database with SSL on Cloudflare #3144
Comments
Running into the same problem. |
You will have to use Hyperdrive. |
@krakz999 could you elaborate a bit? I don't have much experience with hyperdrive (yet) and would like to be able to respond better to CF related issues. 🙏 |
@brianc, I just got it to work using Hyperdrive: https://developers.cloudflare.com/hyperdrive/ You just create a new Hyperdrive in Cloudflare. Bind it to the worker [[env.production.hyperdrive]]
binding = "HYPERDRIVE"
id = ""
localConnectionString = "postgresql://postgres:postgres@localhost:54322/postgres" You can then access in worker as ENV HYPERDRIVE: Hyperdrive; Then new up a pg client like this: this.client = new Client({
host: env.HYPERDRIVE.host,
user: env.HYPERDRIVE.user,
password: env.HYPERDRIVE.password,
port: Number(env.HYPERDRIVE.port),
database: env.HYPERDRIVE.database,
}); It does not require setting the ssl certs. |
This is an awesome writeup - I'll write a documentation page about it (linking back to this issue w/ credits) once I'm back from vacation. Thank you so much! I assume this is safe to close at this point? |
@Daniel-Ash, hi yes, from my understanding Hyperdrive maintains an open TLS connection to the Postgres DB. So, you don't need SSL to connect to Hyperdrive as Hyperdrive is already connected to your DB using TLS. |
Hi,
Thanks for this library. We are using Cloudflare Workers and trying to connect to a database that requires SSL. The application crashes with "Error: Connection terminated unexpectedly".
Is there a way to connect to a db with SSL from CF using this library?
The text was updated successfully, but these errors were encountered: