Web组件、多环境中的跨域API调用
我有两个问题:
1)
我正在 Angular 中开发一个 Web 组件。在我们的项目中,我们有多个测试环境+生产环境。假设域上有多个 API,如下所示:
https://domain.dev1.com/api/v1< /a>
https://domain.dev2.com/api/v1
https://domain.dev3.com/api/v1
https://domain.prod.com/api/v1
Web 组件必须在所有环境中运行。重要的事实是,该 Web 组件将在与 API 不同的域上工作。 (假设https://anotherdomain.com)。如何正确配置呢?我正在考虑使用这些 url 的 4 个不同的environment.ts 文件。比如:
file: environment.dev1.ts
export class Environment {
apiUrl: https://domain.dev1.com/api/v1
}
并在代码中使用这个变量。这是正确的解决方案吗?
2)
在此 Web 组件中,我将使用另一个 Web 组件,该组件配置为在同一域上使用 API(API 的相对路径)。我可以以某种方式创建一个代理来使用这个 API 吗? (正如我之前所说,我的网络组件位于不同的域上)。
希望我能很好地解释一切。
I have 2 questions:
1)
I'm working on a web component in Angular. In our project, we have multiple test environments + production. Assume there are multiple APIs on domains as follow:
https://domain.dev1.com/api/v1
https://domain.dev2.com/api/v1
https://domain.dev3.com/api/v1
https://domain.prod.com/api/v1
Web-component must be working across all environments. Important fact is, that web-component will be working on DIFFERENT domain than API. (lets say https://anotherdomain.com). How to configure it properly? I was thinking of 4 different environment.ts files with these urls. Sth like:
file: environment.dev1.ts
export class Environment {
apiUrl: https://domain.dev1.com/api/v1
}
and use this variable in code. Is that proper solution?
2)
In this web-component I will be using another web component, that is configured to use API on the same domain (relative paths to API). Can i make somehow a proxy to use this API? (as I said before, my web-component is on different domain).
Hope I explained everything well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论