persistent URL to access the latest non-production build

when i push to my main branch, my worker runs the production build, and mywebsite.com starts serving the latest commit how can i access my latest development preview link (which is only generated when a dev pushes a commit to a PR, e.g., https://COMMIT-HASH.WORKER-NAME.CLOUDFLARE-USERNAME.workers.dev)
13 Replies
Baran
BaranOP•2mo ago
@texan thread
texan
texan•2mo ago
Thank you! 😊 yeah let’s recap. So you currently deploy to your workers.dev on merge to main, yeah?
Baran
BaranOP•2mo ago
Do you also want main to auto deploy? Or just give you a “preview”? yes, when i push to main I want 2 things: 1. mywebsite.com to serve the latest build (this is already working as expected) 2. some-persistent-url.com (can be autogenerated workers.dev url) to serve the latest build just like step 1
texan
texan•2mo ago
Ah ok, yeah so you would create another environment through wrangler, and do a deploy to that as well. Build + deploy production + deploy other worker
texan
texan•2mo ago
Cloudflare Docs
Environments
Use environments to create different configurations for the same Worker application.
texan
texan•2mo ago
Just extend your main’s deploy command to also have ‘&& npx wrangler deploy -e someotherenv’ That way you have a second worker with a totally separate set of bindings Not sure why you’d want that though? So maybe I’m misunderstanding
Baran
BaranOP•2mo ago
Not sure why you’d want that though? So maybe I’m misunderstanding
i need internal teams to access the latest build (same one as in production), but with development values
texan
texan•2mo ago
Yup, then you’ll want a separate worker via wrangler environments But I would say maybe you ACTUALLY want to test before you push to main 😅
Baran
BaranOP•2mo ago
yep, testers already use the preview links but some devs and PMs need the latest link with dev env values, so they can explore the latest version using the dev db
texan
texan•2mo ago
Right, but you could use the same strategy to upload a version to your development worker before merging 🙂 However you decide! Totally possible 🙂 feel free to create a workers help thread if you get stuck!
Baran
BaranOP•2mo ago
Right, but you could use the same strategy to upload a version to your development worker before merging 🙂
but wouldn't different commits in different PRs override the worker?
texan
texan•2mo ago
You’d do ‘version upload -e staging’ and your preview link will be a non deployed version connected to dev worker If you need a stable name, yeah, it would conflict with each pr But you can get around this too with a custom npm script to do the alias yourself based on the branch (in that case your deploy command for non production would be npm run deploy, and you’d handle the wrangler commands yourself)
Baran
BaranOP•2mo ago
makes sense, i will experiment now. Thank you Will for your help

Did you find this page helpful?