如何为 Heroku 上的暂存和生产环境提供单独的 API?
How can I have separate APIs for staging and production environments on Heroku?
我只是在检查管道在 Heroku 中的工作方式。我希望暂存和生产应用程序相同,只是它们应该访问不同的 API 端点。
我怎样才能做到这一点?
Heroku 鼓励 getting configuration from the environment:
A single app always runs in multiple environments, including at least on your development machine and in production on Heroku. An open-source app might be deployed to hundreds of different environments.
Although these environments might all run the same code, they usually have environment-specific configurations. For example, an app’s staging and production environments might use different Amazon S3 buckets, meaning they also need different credentials for those buckets.
An app’s environment-specific configuration should be stored in environment variables (not in the app’s source code). This lets you modify each environment’s configuration in isolation, and prevents secure credentials from being stored in version control. Learn more about storing config in the environment.
On a traditional host or when working locally, you often set environment variables in your .bashrc
file. On Heroku, you use config vars.
在这种情况下,您可能会使用一个名为 API_BASE
的环境变量,该变量被设置为暂存实例 API 的基础 URL 和基础 URL 您的作品 API 正在制作中。
读取这些值的具体方式取决于您使用的技术,但如果您在您的语言文档中查找“环境变量”,您应该能够开始。
我只是在检查管道在 Heroku 中的工作方式。我希望暂存和生产应用程序相同,只是它们应该访问不同的 API 端点。
我怎样才能做到这一点?
Heroku 鼓励 getting configuration from the environment:
A single app always runs in multiple environments, including at least on your development machine and in production on Heroku. An open-source app might be deployed to hundreds of different environments.
Although these environments might all run the same code, they usually have environment-specific configurations. For example, an app’s staging and production environments might use different Amazon S3 buckets, meaning they also need different credentials for those buckets.
An app’s environment-specific configuration should be stored in environment variables (not in the app’s source code). This lets you modify each environment’s configuration in isolation, and prevents secure credentials from being stored in version control. Learn more about storing config in the environment.
On a traditional host or when working locally, you often set environment variables in your
.bashrc
file. On Heroku, you use config vars.
在这种情况下,您可能会使用一个名为 API_BASE
的环境变量,该变量被设置为暂存实例 API 的基础 URL 和基础 URL 您的作品 API 正在制作中。
读取这些值的具体方式取决于您使用的技术,但如果您在您的语言文档中查找“环境变量”,您应该能够开始。