dev/qa/prod 环境策略的 Nativescript 不同 api 端点

Nativescript different api endpoint for dev/qa/prod environments strategy

我有一个与 Web api 后端对话的 NS 应用程序。我不想在应用程序本身中对 api 基础 url 进行硬编码,因为我需要能够使用不同的 url 来针对不同版本的应用程序进行开发、测试和生产.

例如版本 1.0 正在生产中并指向 https://someapi.com. I am currently working on version 1.1 and I want to point that to https://dev.someapi.com during development and testing because I have API changes as well. Once this version is QA'd and passes app store validation agains the test API. I will push it to production, deploy the API, and point the version 1.1 from https://dev.someapi.com to https://someapi.com.

目前,我有一个数据库 table,每个版本和环境都有 api 端点,所以如果我需要对 1.1 版应用程序进行质量检查,我会在加载时查询数据库应用并获取此版本和环境的 api 端点。

有更好的方法吗?

谢谢。

Nativescript CLI & Webpack 中使用环境变量。您可以根据要构建应用程序的环境来配置 URL。

如果您通过 Webpack docs.

,还有很多类似的其他方法