如何使用Create React应用程序部署单独的预生产和生产网站?

发布于 2025-01-20 18:45:06 字数 782 浏览 0 评论 0原文

目前,我已将网站部署到一个子域中,用于使用Firebase Hosting:test.mydomain.com

该测试域包含我的.ENV和.ENV生产文件中的测试API键。我将此域视为可以进行端到端测试的地方,并允许公共用户以公共测试人员的身份在网站上玩耍。在我的客户端代码中,我将模拟器初始化用于本地开发/测试,我有类似的东西:

if (process.env.NODE_ENV === 'development') {
    initEmulators();
} else if (process.env.NODE_ENV === 'production') {
    ...
    // Currently this section applies to test.mydomain.com
}

问题是,我不希望test.mydomain.com被称为'生产”因为它没有我的实时API键,所以只需测试API键即可。如果可能的话,我希望理想地将其称为我的代码中的某种“预生产”环境。因此,当我想将实际站点部署到mydomain.com时,它将包含其自己的实时API键,与test.test.mydomain.com中的测试键分开。

有没有办法通过创建React应用程序和Firebase托管来牢固区分“预生产”和实际生产?

我还将如何使用节点/云功能区分后端的两个环境?

我只有一个Firebase项目可以存储所有数据和托管信息,我想避免在可能的情况下创建第二个项目。我正在使用纱线作为软件包经理。

Currently, I have deployed my website to a sub-domain for testing using Firebase Hosting: test.mydomain.com.

This test domain contains my test API keys in my .env and .env-production files. I treat this domain as somewhere where I can run end-to-end tests as well as allow public users to play around on the site as public testers. In my client code, where I initialize my emulators for local development/testing, I have something like this:

if (process.env.NODE_ENV === 'development') {
    initEmulators();
} else if (process.env.NODE_ENV === 'production') {
    ...
    // Currently this section applies to test.mydomain.com
}

The issue is, that I don't want test.mydomain.com to be referred to as 'production' because it doesn't have my live API keys, just test API keys. I want to ideally refer to it as some sort of "pre-production" environment in my code if possible. So that way when I want to deploy my actual site to mydomain.com, it will contain its own live API keys, separate from the test keys in test.mydomain.com.

Is there a way to firmly distinguish between "pre-production" and actual production with Create React App and Firebase hosting?

How will I also be able to distinguish between the two environments on the back end using Node/Cloud Functions?

I have only one Firebase project to store all my data and hosting info, I'd like to avoid creating a second project if possible. I am using Yarn as a package manager.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文