I'm trying to store URL's in my environment variables. So for instance
ENV['SET_COOKIE_URL'] = 'http://domain.com/setcookie'
In my application layout page, I'm trying to do this:
window.top.location = '<%= ENV["SET_COOKIE_URL"] %>';
When I try this, it always returns '' (empty string).
Can you not store and output URL's in environment variables?
If you just added this environment variable, perhaps re-starting your server would help pickup the environment change. I don't see any reason why you won't be able to use that environment variable in your view other than just re-booting your server.
Related
I've been looking around my machine to see where the postman environment variables are stored. I've looked under AppData\Local\Postman, and C:\Users\username\Postman folders, and haven't found a config file that has a last modified date matching my change of environment variables.
I know I can export the environment variables, but I want to search over the current variables. And the exports don't include the current values, unless they replace the initial value, which I want to keep.
There are still ways to get around this. But I want to write a simple command to fetch some current environment variables via cmd, ex using grep.
So is there a way to check for the current environment variables? Where are they stored?
I don't think this will be a successful attempt. Postman seems to use a database, e.g. leveldb, according to information I found here. That will be stored as a binary file on your disk.
You can, however, have a look into the DB by going to View => Developer => Show DevTools and then going to Storage => IndexedDB => variable_sessions => workspace. I can find a current value for an environment variable like this:
But I don't see a way to search in this other than by keys which are uuids and not variable names or values.
All in all, exporting your environments into a text file might be the easiest option.
I would like to use an environment variable within template.html so that I can change the content in the head for all pages based on where I'm running the app. Is this possible?
I never found a way to put environment variables in template.html, but I passed what I needed through server.js, picked it up in _layout.svelte, and included it in a <svelte:head> element.
https://dlang.org/library/std/process/environment.html allows getting a particular environment variable.
But I see no way to get all environment variables or the list of all environment variable names.
What is the right way to retrieve the full environment in D?
In fact, I want to pass some environment variables to a child process. What is the right way to do it?
There is no need to get all variables to pass to a child process; that is the default. If you are using the std.process library, you can pass null for environment to keep the existing one entirely, or a set of just the keys and values you want to change to get just them changed, and the rest inherited.
This would be very useful for storing API keys or other sensitive information. From what I understand, you can use config files locally but they won't work on meteor.com, but I heard a rumor that environment variables were soon to be supported, or are already as of a recent release, but I can't find any examples.
Can someone provide an example of how to retrieve a value from an environment variable or some other safe location?
You can actually access the process object to retrieve environment variables in Meteor. In essence, just do the same as in this solution
After some thought, storing them all in a .js file inside an object literal, adding that file to the .gitignore, and checking in a corresponding .js.sample file with dummy or blank values would do the trick.
There's a much better way to handle environment variables. If you come from Ruby on Rails you're used to setting your environment variables in your .ENV file or in your config/application.yml file.
Meteor handles environment variables in a similar way.
Create settings.json file
Inside your server folder in your project, create a file and name it settings.json. Add this file to your gitignore file.
Inside this JSON file, you can save any environment variables you need.
{
"facebookAppId": "6666667527666666",
"facebookAppSecret": "00004b20dd845637777321cd3c750000",
"amazonS3Bucket": "bucket-name"
}
Loading the environment variables
To use these values inside your app during runtime, start Meteor with a --settings option flag.
$ meteor run --settings server/settings.json
Use the values
To use the values, just call the Meteor.settings object.
ServiceConfiguration.configurations.upsert(
{ service: "facebook" },
{
$set: {
appId: Meteor.settings.facebookAppId,
secret: Meteor.settings.facebookAppSecret
}
}
);
That's all there is to it! Keep your settings safe, and do not commit your keys.
I have a scenario where I want my CoffeeScript file to access an environment variable like an API key value. This works fine locally but it isn't working when I push it up to heroku.
The file is named something like myfile.js.coffee.erb
I am setting the value like this
api_key = '<%= ENV['SERVICE_API_KEY'] %>'
I know the values are set in heroku and I have triple checked the spelling, etc. I know it is being processed since the resulting JavaScript file looks like this
var api_key;
api_key = "";
Is there something I need to do when precompiling my assets where I can tell it to access environment variables? I admit that I am new to CoffeeScript and the Rails asset pipeline. Is there another more accepted way of doing this? I don't want to embed it in the file for obvious reasons.
So since the API key is going to be visible to those interested whether it's in the javascript file or the html file and since you really don't want to be generating a new .js file every request, the easiest solution I've found to the same problem is to put the key in your layout.html.erb file.
You can throw it in a script tag, use a data-attr, whatever floats your boat, but it works and you get the benefit of a dynamic variable and having to render one less file.
And you can still use the <%= ENV['api_key'] %>. You'll have to fetch the variable in your js (or coffee), but that's pretty trivial.
Try this
heroku labs:enable user_env_compile -a myapp
then deploy again
Worked for us!
all credits to this guy:
Heroku always runs assets:precompile with the production environment for Rails 3.2