Deno Fresh: client side check dev or production
For my Deno Fresh app, I want to do a simple check from the client-side code to see whether it's in development mode or production deployed mode.
Use case is: I want to point my API to my localhost if it's in development, otherwise point the API to production server.
How can I do this in Deno Fresh?
1 Reply
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your description, you might consider using environment variables to differentiate between development and production environments.
In a typical setup, you could have an environment variable that you set differently depending on the environment. For example, you might have a
DENO_ENV
variable that is set to development
in your development environment and production
in your production environment.
On the client side, you could then have a script that checks this variable and sets the API endpoint accordingly. However, since environment variables are server-side and not exposed to the client-side directly, you would need to inject this information into your client-side code during the build process or serve it through an API endpoint.
Here's a very basic example of how you might approach this:
Please note that this advice is not based on the Deno documentation, and you should double-check the accuracy of this advice. It's also important to ensure that you do not expose any sensitive information to the client-side.Helpful Links:
Fresh 1.0
Deploy to production | Fresh docs
Build and Ship Astro Sites with Deno and Deno Deploy
Simple API server | Deno Docs
Fresh 1.1 - automatic JSX, plugins, DevTools, and more
CI and GitHub Actions | Deno Docs
Testing API | Deno Docs
Using deployctl on the command line | Deno Docs
Running locally | Fresh docs