🚀 Feature Request: Get worker domain/url at build time #13482
Replies: 5 comments 1 reply
-
|
Hi, thanks for the feature request :) - would be great as well to know more specifics about your use case and how/why you need the preview url at build time? |
Beta Was this translation helpful? Give feedback.
-
|
I'm building dev tools that help deal with config more generally, so I don't have a specific use case myself... But often it is useful to know the URL at build time so you can include it as a static replacements within your bundled code, use it within config files fed into other tools, or use it when interacting with external services that must be set up as part of a larger deploy process. For example say you need to generate some JSON config file that will be fed into another tool, and part of that config file is the current URL. |
Beta Was this translation helpful? Give feedback.
-
|
We also need this to migrate from Pages to Workers for our static sites. Our use case is as follows: We need to generate a RSS feed at build time and to allow us to test the RSS feed in preview environments. We need to use absolute URLs for the feed as the RSS specification doesn't support relative URLs. Manually setting a variable for each test deployment simply isn't a viable option. It works for production as the URL is stable. CF_PAGES_URL worked perfectly for this requirement and having an equivalent in Workers would enable our migration path. |
Beta Was this translation helpful? Give feedback.
-
|
Another use case is a static website which wants to explicitly name itself. Say you're deploying to https://abcdef01-website.example-cf.workers.dev/ and on that very website you want the string "Hello, you are visiting https://abcdef01-website.example-cf.workers.dev/!" to appear. Now this in itself might seem a bit nonsensical, but there are quite a few cases where such self reference is preferred. For example, "Just run |
Beta Was this translation helpful? Give feedback.
-
|
I need this for setting BETTER_AUTH_URL for the base url |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the solution
Similar to #2410, when we are building a worker, sometimes we want to know the URL of where it will be deployed while building it. For production cases the main URL will be known, and likely aliased to a non workers.dev URL, but for previews, there's no way to know the "version prefix" until after the version is created. Adding different environments into the mix further complicates things. As does supporting local wrangler dev url.
Possible solutions:
Figuring this out sooner rather than later would be good, considering what is happening with the workers builds git integration and automatically doing branch/PR builds. We'll have same issues there and even more cases to deal with.
Beta Was this translation helpful? Give feedback.
All reactions