如何在运行时或部署时设置环境变量以选择正确的配置

编程入门 行业动态 更新时间:2024-10-26 14:40:03
本文介绍了如何在运行时或部署时设置环境变量以选择正确的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

1.总结问题

我们正在使用配置模块(节点),该模块允许我们使用Firebase托管应用设置各种配置选项,例如数据库设置或其他api端点设置.

如果APP_ENV变量设置为'dev',则它指向dev api的实例和数据库设置,与'test'和'prod'相同.

在容器中运行时,我们仅具有一个shell脚本,该脚本可设置APP_ENV然后运行服务器,并选择正确的配置设置.

我们如何通过Firebase托管做到这一点?

使用: github/lorenwest/node-config

2.提供背景,包括您已经尝试过的内容

查看了文档,却一无所获.

3.显示一些代码

github/lorenwest/node-config

4.描述预期和实际结果,包括任何错误消息

预期:根据环境(开发,测试,生产),部署到Firebase并让Web应用访问正确的资源(API端点,数据库设置).

解决方案

我遇到了类似的问题. 我用NODE_CONFIG_ENV覆盖了NODE_CONFIG

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

参考文献: [1] github/lorenwest/node-config/wiki /环境变量

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: github/lorenwest/node-config

2. Provide background including what you've already tried

Looked over documentation, found nothing.

3. Show some code

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

解决方案

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]github/lorenwest/node-config/wiki/Environment-Variables

更多推荐

如何在运行时或部署时设置环境变量以选择正确的配置

本文发布于:2023-11-24 05:43:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624140.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境变量   正确   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!