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).

user10664542
  • 1,106
  • 1
  • 23
  • 43
  • 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. – Doug Stevenson Sep 12 '19 at 19:23
  • 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](https://firebase.google.com/docs/hosting/reference/rest/v1beta1/sites.versions#Version). But labels are generally used for billing report. You don't find any location where to set an env var? – guillaume blaquiere Sep 12 '19 at 21:03
  • 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:** https://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? – user10664542 Sep 17 '19 at 14:52

1 Answers1

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

Sanyam Jain
  • 2,925
  • 2
  • 23
  • 30