Bootstrap your Cloudflare Worker to connect to a pgEdge database
This is a simple Cloudflare Worker that connects to a pgEdge database. Use it as a starting point for your own project.
To find your pgEdge connection string, go to the pgEdge console. If you have not yet signed up for pgEdge, you can easily sign in with your social accounts. Creating a new database is free and takes less than a minute.
Once you've reached the console, navigate to the database you want to connect to. In the Connect to your database
section, you will find your username, password, and the host is the Domain
.
The database connection is configured using the DB
environment variable. The value should be in
connection string format, e.g. postgres://user:pass@host/dbname?sslmode=required
. This value
can be added to Cloudflare using wrangler
like so:
wrangler secret put DB
Additionally, you should make a .dev.vars
file and set the DB
environment variable there as well
so that you can run the worker locally.
You will need to set two repository secrets in your repo in order to deploy to Cloudflare.
The first is CF_ACCOUNT_ID
which is your Cloudflare account ID. The second is CF_API_TOKEN
which is a token that you can generate from the API Tokens
section of the Cloudflare dashboard.