I've been using Replit.io as a means of hosting a bot I built. As a part of that I have to store some API keys / secrets / or ENV vars. The built in tools for this: https://docs.replit.com/tutorials/storing-secrets-and-history
are super helpful, and work, but I recently got hung up where these variables were returning as undefined. How can this be solved?
Simple refresh of the page after adding and saving the variables then waiting a minute or two before re-starting the bot itself.
Related
Recently I've been playing around with the edge-runtime and finally set things to work normally on my local environment with different routes path handled by some of my custom implementations under fetch event. and these are running under edge-runtime
And with some digging around, to be able to deploy what I've made to Vercel I have to convert my project to nextjs and exposed the config to ensure it to run on the experimental-edge runtime
What I want to ask here is
Is there a way I can deploy my edge-runtime API to Vercel without having to convert my project to NextJS
Thank you
No, Next is required.
use Cloudflare Workers instead for legacy fetch handler support
I have deployed a remix application on Vercel. Further, I have defined some environment variables in Vercel and want to perform some checks and use env variables in my app:
if (process.env.NODE_ENV === 'production') {
setPaths({
path: process.env.prod_path,
})
}
It gives me error, process is not defined. I even tried adding process && in the if statement, it did not help.
Second, I am unable to even set the env variables locally. I followed remix docs but it gives me undefined every time when I console.log as mentioned in the docs.
Any guide/pointer towards using environmental variables in remix would be really helpful.
I was able to solve this problem. I was using loader/useLoaderData to access server side environment variables. The problem was that I was trying to call these at component level. Apparently, we can only call them at the route level.
I'm not sure, but the name of the function (setXXX makes me think this is the setter of a hook), makes me think you are trying to use process.env in the browser, but process.env is only available in server-side code, if you want to use env variables in your react app you can use this guide to send the variables from the server side to you react app. If this code is server side code, maybe it's worth making a reproduction in stackblitz so we can have a better look at it.
I'm stuck on what seems like a simple task. I want to run a weather app I built in Svelte and run it on Replit. The app uses an API with a key, so I added my key to Secrets in Replit and gave it the name MY_API_KEY.
In the file that calls the API, I used the following:
const MY_API_KEY = process.env.MY_API_KEY;
Unfortunately, that doesn't work. My app doesn't load. When I change the variable in my file to include the key itself, the app runs fine, so I must not be calling up the environmental variable right. Does anyone know how this works in Svelte? I'd appreciate any help.
The base Svelte template on Replit uses Vite for building it's apps. This means you can do it the Vite way:
Call your environment variables something like VITE_ApiKey=123
And in your code use import.meta.env.VITE_ApiKey
Note that this only works for environment variables prefixed with VITE_
I'm new on this technology (studying for now) and I have a doubt on how to properly work with the Apps.
For example, I have an app-gateway with 2 instances (Traefik), and in there I'm using env variables like RESTRICTED_NETWORK_01 and RESTRICTED_NETWORK_02.
I want to replace de IP value of RESTRICTED_NETWORK_02 and apply the change without any impact to the gateway/redirect users service.
Should I just use the command:
cf set-env app-gateway RESTRICTED_NETWORK_02 [ipvalue]/24
then
cf restart-app-instance app-gateway 0
wait until the instance restarts and apply
cf restart-app-instance app-gateway 1
Is it the right steps I should follow for this situation?
Any help?
cf restart-app-instance app-gateway 0
This will probably not do what you want, at least not reliably. This command works by terminating your application instance, which then allows it to be restarted. It's typically useful if you have an app instance that's in a bad state but hasn't crashed or failed health checks (or for demos where you need to make an app crash).
In terms of env variables, it doesn't work so well. This is because the env variable changes you've made reside in Cloud Controller, but your application runs on the scheduler (Diego). The scheduler has a copy of data from the Cloud Controller that tells it how to run the app, including environment variables that should be set. The command you're referencing doesn't result in Cloud Controller updating the application definition that it has sent to the scheduler (Diego). It simply results in the process being terminated and restarted by the scheduler using the same definition.
Your mileage may vary on this one, as I've heard some reports of people saying that cf restart-app-instance works for updating env variables (I don't really see how it would, but I haven't investigated their claims either). You could try it and see, but the stories I've seen have typically ended with problems. tl-dr it doesn't consistently work.
To reliably update env variables, you need to use cf restart. This will restart all application instances.
What you should do to restart app instances without downtime is to use the cf restart --strategy=rolling option (available in version 7 of the cf cli). This will roll out the changes and so long as you have multiple application instances, should not result in downtime.
i am trying to store my api keys in a variable via the terminal but i am unsure why it is not saving/storing my api keys.
for example, in the terminal when i type the below:
export GMAIL_USERNAME="myname#gmail.com"
then when i type in env i can see the varaibale has been stored:
but when i restart my terminal the variable GMAIL_USERNAME="myname#gmail.com" is no longer there
could one tell me where i am going wrong? all i would like to do is
store in development my api secret keys in a variable. your help would
be much appreciated
While you can persist environment variables by adding them to a script that gets called on shell startup, that approach has a few problems.
The biggest problem is that they are available globally across your shell, and not scoped to a project.
What happens if you have another project, and want to use a different gmail account?
A better solution is using dotenv or direnv and set those environment variables for the current project only.