Reputation: 1742
I'm trying run Remix.run with Cloudflare workers. How might I access environmental variables related to Cloudflare data persistence services (such as D1) in Remix.run data loader functions?
I have "bound" the worker via wrangler.toml
and can access the service via wrangler.
[[ d1_databases ]]
binding = "DB" # i.e. available in your Worker on env.DB
database_name = "Example"
database_id = "123-456-789"
I'm able to access other environmental variables from the global scope using .env.vars
but can't seem to access DB
.
Upvotes: 0
Views: 1337
Reputation: 8457
The DB binding works for me using the new module syntax. Note that this is distinct from the old service worker syntax. Durable objects require module Workers - perhaps this is also true for the new D1?
Upvotes: 0
Reputation: 20312
In Cloudflare Workers, environment variables are exposed on the global
object. I recommend making them all caps.
declare var DATABASE_ID: string
console.log(DATABASE_ID)
Upvotes: 1