custom binding with CLI `wrangler versions`

I have this dynamic value that is in my github actions. i want to upload a version with a specific binding to it. In essence i want this to work: HUBS_EMBED_URL=https://google.com wrangler versions upload for some reason this does not end up as an env variable in the version 😦
4 Replies
Gravite2090
Gravite2090•6mo ago
If you only need that variable to change for a few environments, say staging and production, try adding those environments to your wrangler config file - which is going to be the source of truth when you run wrangler commands. So something like this: wrangler.jsonc

...
"env": {
"staging": {
"vars": {
"HUBS_EMBED_URL": "https://staging.google.com/"
}
},
"production": {
"vars": {
"HUBS_EMBED_URL": "https://google.com/"
}
}
}

...
"env": {
"staging": {
"vars": {
"HUBS_EMBED_URL": "https://staging.google.com/"
}
},
"production": {
"vars": {
"HUBS_EMBED_URL": "https://google.com/"
}
}
}
--- Alternatively specify different config files in the command itself: wrangler versions upload --config wrangler.staging.jsonc --- OR if it is truly dynamic, eg. changes with every build, you would likely need to build your config file via a script as part of your ci/cd then run the wrangler command. Personal opinion: If you are considering building dynamic config files step back and see if you have a simpler path forward, like adjusting params to downstream APIs in your app code dynamically. Hope this helps! - not an expert
top kek
top kekOP•6mo ago
it’s the result of another deployment - i create a version of app_1 in my branch - i want to use app_1’s URL in my app_2 where i will iframe it I guess modifying the wrangler file ahead of building the app with the var is an idea, just seems hacky
Gravite2090
Gravite2090•6mo ago
Maybe there is a simpler solution of storing an object in KV attaching versions to URLs. You can use wrangler to get KVs at build. Sorry I don't know a super clean fix here, building dynamic wrangler configs every time does seem a bit messy.
top kek
top kekOP•6mo ago
it’s a per-PR deployment surgically altering wrangler.jsonc worked fine, it’s crap but works

Did you find this page helpful?