How to set env var at runtime or deployment to select the right config
Asked Answered
H

1

1

1. Summarize the problem

We are using a configuration module (node) that allows us to set various configuration options, for example database settings or other api endpoint settings with our firebase hosted app.

if the APP_ENV variable is set to 'dev', then it points to the dev api's instances and database settings, same with 'test', and 'prod'.

When running in a container, we simply have a shell script that sets APP_ENV and then runs the server, and the right configuration settings are chosen.

How do we do this with Firebase hosting?

Using: https://github.com/lorenwest/node-config

2. Provide background including what you've already tried

Looked over documentation, found nothing.

3. Show some code

https://github.com/lorenwest/node-config

4. Describe expected and actual results including any error messages

Expected: Deploy to Firebase and have the web app access the correct resources (api end points, database settings), based on environment (dev, test, prod).

Hygienic answered 12/9, 2019 at 19:10 Comment(3)
I'm not sure I understand your question. Firebase Hosting doesn't run any of your node code. It just serves static content, or proxies to Cloud Functions or Cloud Run.Ankylose
Hard to find information... Did you try to set label in your hosting config. with the key= APP_ENV and the value = your env. I only found this in the REST api. But labels are generally used for billing report. You don't find any location where to set an env var?Fanchan
When the code runs, I want it to select out of a config file the right section for it's runtime config. The different sections of the config file are 'dev', 'test', 'prod'. Please Read: github.com/lorenwest/node-config to understand what I am trying to do. This is very typical of enterprise projects to have different runtime environments: 'dev', 'test', 'prod' of the same code, but different settings, for example each runtime instance also has a separate: 'dev', 'test', and 'prod' API endpoint with 'dev', 'test', and 'prod' access keys, all different. Comprende?Hygienic
B
0

I was facing a similar problem.
I used NODE_CONFIG_ENV to override NODE_CONFIG

//for production
process.env.NODE_CONFIG_ENV = "default";

//for development
process.env.NODE_CONFIG_ENV = "production";

References:
[1]https://github.com/lorenwest/node-config/wiki/Environment-Variables

Berthold answered 11/10, 2019 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.