Meteor.settings undefined in production - meteor

I am deploying to DigitalOcean using Dokku, but for some reason, my all references to Meteor.settings returned undefined
Any idea as to why this is?

Once the app is deployed, to get the settings you need to set the METEOR_SETTINGS environment variable with the JSON for your settings.
METEOR_SETTINGS=`cat settings.json` ROOT_URL=... MONGO_URL=... node main.js

Related

Error validating datasource `db`: the URL must start with the protocol `mongo`

ERROR PrismaClientInitializationError: Invalid
`prisma.chat.findMany()` invocation:error: Error
validating datasource `db`: the URL must start with the
protocol `mongo`.
--> schema.prisma:10
| 9 | provider = "mongodb"
10 | url = env("DATABASE_URL")
| Validation Error Count: 1
Different type of methods I've tried so far:
Renaming mongodb to mongo in database URL
Removing the quotes in vercel enviroment variables
adding the enviroment variable to vercel.json
All my environment variables are already in my vercel environments for my project
Works perfectly fine in Dev -> Build -> Start in vscode.
How do you deploy on vercel with prisma mongodb URL error?
Ive seen the same error for others but with different db.
You need to define your environment variables in Vercel. Vercel won't have access to your local .env file.

process.env variables undefined in Nextjs

I'm reading undefined for my enviroment variable.When I console log process.env I can't seem to find the variable I defined In my .env file at the root directory.
.env.local file
privateKey="444455....."
scripts/hardhat.config.js
mumbai: {
url: 'https://polygon-mumbai.g.alchemy.com/v2/3333.....',
accounts: [process.env.privateKey]
},
Is it because I'm reading process.env outside of pages? I aslo tried prefixing like NEXT_PUBLIC_privateKey="0033....." and then reading it process.env.NEXT_PUBLIC_privateKey but value would only show inside pages folder and not in scripts/hardhat.config.js
Make sure you have installed and initialized the doting NPM package that is needed to use environment variables.
FINALLY WORKS
I ended up adding the dotenv AS SOMEONE SUGGESTED and starts reading.
Note to self
Enviroment variables outside next.js pages need that dotnev thing;

Firebase CLI suddenly ignoring environment variables on Functions deployment

I have a Firebase code project with Functions meant to be deployed to multiple Firebase projects over multiple regions.
I used to set the deployment region like this:
return functions
.region(process.env.REGION)
// ...
and used this command to deploy:
$ REGION=us-central1 firebase deploy --only functions
it worked like a charm until recently. Now it seems to completely ignore REGION=us-central1 even if I export it before I run firebase deploy.
EDIT 2022-06-13 - Possible solution
I changed the code to dump the contents of process.env to a file during deployment. This is what I got:
{
"FIREBASE_CONFIG": "{\"projectId\":\"REDACTED\",\"storageBucket\":\"REDACTED.appspot.com\",\"locationId\":\"us-central\"}",
"GCLOUD_PROJECT": "REDACTED",
"CLOUD_RUNTIME_CONFIG": "{REDACTED}",
"__CF_USER_TEXT_ENCODING": "REDACTED"
}
so definitely is not the same list of variables I have in my local environment.
I could use the locationId from FIREBASE_CONFIG to get the target location, or CLOUD_RUNTIME_CONFIG (it contains the dump of the functions .config() object, so I could set the target there).
I also believe that I could use the .env and .env.{project alias or ID} files and their contents would be available in process.env at deployment time.
As per Osvaldo López's suggestion, here are some other details:
Running on MacOS
No errors are reported
No recent changes to the CLI
Any input would be very welcome! Thanks.

Env vars are undefined in Nextjs v12.0.8

I created a .env.local file and tried to console process.env.TEST (test env var) but I'm getting undefined. It seems process.env is always empty.
I restarted the server but I still don't see the env vars. I even tried to start a new empty project and process.env is still empty.
Am I missing something? All the other posts I see seem to have figured it out but I still can't.
My .env.local file is on the root level. I also tried to append the var with NEXT_PUBLIC, but that didn't help.
By convention, React env variables must be prefixed with REACT_APP_ in order to be used with process.env. In the case of Next.js, you can put them in the .env.local, but they would only be available in the Node.js environment. If you need to make them available in the browser, you need to prefix them with NEXT_PUBLIC_.
Refer to the documentation for more details.
Another way (more old school Next.js) would be to have a next.config.js file.
A possible config would be:
const conf = {
env: {
myVar: process.env.MY_VAR,
},
};
module.exports = conf;
Then you could simply use process.env.myVar inside your code. See this page for more information.

Auth0 and Next.js deployed to Vercel: Location header error

I started with this sample repo: https://github.com/vercel/next.js/tree/canary/examples/auth0
My current repo: https://github.com/rebeccapeltz/next-auth-app-1
Login/Logout work fine locally. When I deploy to Vercel and logout I get this message in the browser:
Invalid character in header content ["Location"]
I've double checked the Auth0 env variables and they seem correct. Login works fine on Vercel. Can't figure out how to troubleshoot the header Location value that is causing the problem.
Nothing much going on yet and easy to reproduce: https://next-auth-app-1.now.sh/
Solved this by removing all env variables added to the Vercel online application settings. Then added the secrets using the now CLI now secrets add and deployed the app by setting up other env variables in now.json and using now --prod. Working OK now. For further external env secrets and references, I'm wondering if t's better to add them via now.json or to use the online settings GUI. One thing that wasn't clear is that when you add variables with now add secrets you need to prefix the value in the now.json with #. Kind of like accessing bash env variables with $. So after adding secrets my now.json looks like this
{
"build": {
"env": {
"AUTH0_DOMAIN": "<name of auth0 domain>",
"AUTH0_CLIENT_ID": "<what you get from auth0>",
"AUTH0_CLIENT_SECRET": "#auth0_client_secret",
"REDIRECT_URI": "<name of vercel app or domain name>/api/callback",
"POST_LOGOUT_REDIRECT_URI": "<name of vercel app>/",
"SESSION_COOKIE_SECRET": "#session_cookie_secret"
}
}
}
Should you add all env using secrets add and then just reference by name in the now.json? not sure.

Resources