Is there a way to set different environment variables for different routes the worker executes on? My use case would be a language redirect worker that redirects from domain.tld to domain.tld/en/, domain.tld/de/ and so on based on Accept-Language.
I want to activate this worker on multiple domains where I can set different website urls, available languages and a default languages for each website.
I guess what I could do is check the Request domain and change the variables based on that, but I would prefer a more clean solution.
Environment Variables are allocated per-script only, are limited in amount (max 30) and very limited in size (max 5kb). So I’d suggest using KV for this and if you want to have it as “secure” as a KV you can encrypt the KV strings using WebCrypto API.
I think you misunderstood, the same worker script would execute on different sites/domains, as the redirection logic is the same across our multi-language websites.
The things different for each website are the following 3 variables. I would prefer not to duplicate the whole worker in order to change only those 3 variables.
Thank you, that is exactly what I was looking for. From the documentation it was initially not clear to me that custom environments other than staging and production can be defined, but makes sense!