Provide preset environment variable to distinguish Preview vs Production Deployments
It would be useful for code to be able to determine which type of deployment it is running within via environment variable. Right now I have to manage this with a flag in code that only lives in the main branch, and be careful not to invalidate that flag during merges.
I can give more details on my specific use case if it is of interest.
I agree that I need this feature.
For my use case, I want to access the development database from the preview deployment and the production database from the production deployment. So I need a way to distinguish between preview and production.
I completely agree. For my external DB credentials I keep two similar sets of env:
MY_DBNAME_PREVIEW=my-db-dev
MY_USER_PREVIEW=my-dbuser-dev
MY_PASS_PREVIEW=123dev789
MY_DBNAME_PROD=my-db-prod
MY_USER_PROD=my-dbuser-prod
MY_PASS_PROD=123prod789
It's because a production build at deno deploy receives a shorter and a longer URL at the same time,
latter being indistinguishable with any other preview builds.
To distinguish PROD or REVIEW, I use hostname from user's request.
When the URL is shorter, it is likely about PROD, otherwise PREVIEW.
But there is no guarantee. PROD also receives a longer URL and users can call it without notice.
So I have to keep both _PROD and _REVIEW variables just in case, and everytime I receive an incoming request I have to run a function like targetFromRequest(req): Target { ... } to obtain the target type. This is request based, not service (build) based, which is inconvenient.
We need a more straightforward and stable solution to tell if it's PROD or REVIEW.
It cannot be discerned from this URL if it's a prod or preview deployment: "{project_name}-{deployment_id}.deno.dev"