简体   繁体   English

.NET 微服务和 CORS

[英].NET Microservices and CORS

Please, keep in mind that I am just getting to know microservices.请记住,我刚刚开始了解微服务。
One thing that came to my mind is connecting CORS with microservices.我想到的一件事是将 CORS 与微服务连接起来。
I'm creating a project using .NET Core 6 as a backend, and Angular as a Frontend,我正在创建一个项目,使用 .NET Core 6 作为后端,Angular 作为前端,
this part won't be a problem, but CORS and Microservices, ughh:D这部分不会有问题,但是 CORS 和微服务,呃:D

The question is: Do I need to create CORS policy inside my microservices or is it unnecessary?问题是:我需要在我的微服务中创建 CORS 策略还是没有必要?
Ocelot will be used to create API Gateway, and I'm confused if CORS is also needed. Ocelot 将用于创建 API 网关,我很困惑是否还需要 CORS。

I have some experience in creating SPAs and enabling communication with CORS between .NET backend API and Angular client.我在创建 SPA 和启用与 CORS 在 .NET 后端 API 和 ZC31C335EF372283C45Z1B118 客户端之间的通信方面有一些经验。 I have used there CORS Policy, but my uncertainty is about using CORS in microservices.我在那里使用过 CORS 策略,但我不确定是否在微服务中使用 CORS。

I searched in Google with various configurations of this question我在谷歌中搜索了这个问题的各种配置
and nothing noteworthy popped out in front of my eyes.并没有什么值得注意的东西出现在我眼前。

Please, help me with that:)请帮帮我:)

If you have an API Gateway in front of all your microservices, then you only need to set CORS in the API Gateway and it would work as if you add CORS Policies to all microservices at once. If you have an API Gateway in front of all your microservices, then you only need to set CORS in the API Gateway and it would work as if you add CORS Policies to all microservices at once.

                         ┌───────────────┐
                         │               │
                   ┌─────┤ Microservice1 │
┌─────────────┐    │     │               │
│             │    │     └───────────────┘
│ API-Gateway ┼────┤
│             │    │     ┌───────────────┐
└─────────────┘    │     │               │
      ▲            └─────┤ Microservice2 │
      │                  │               │
      │                  └───────────────┘
      │
Set CORS here

This is the preferred approach because you do not need to spread CORS policies across all microservices.这是首选方法,因为您不需要在所有微服务中传播 CORS 策略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM