Why is my proxy redirecting to a different port than my API?

Viewed 62

I've wasted more than two weeks of one of my colleague's and my time on this issue. Any help would be greatly appreciated. Thank you for your time in advance. Here is the setup:

Web app created with Visual Studio 2022 (pre-generated code, I hardly touched the configuration and the Program.cs), .Net Core 6.0, Angular 13, Identity. When I launch, a command indicates that the SPA Proxy is beeing launched as well, and the URL given to me by IIS is https://localhost:44384. So I go on there. On there, it says that "the SPA Proxy will redirect you to https://localhost:44484". Why? It indeed redirects me to 44484. At first, I didn't care, I started working on my controllers, my UI, etc. It was not preventing the API from working at all. But now, I'm in a pickle.

Because, I now need to get the user email from my controller. Pretty basic stuff right? HttpContextAccessor and you're done. But NO! Because the ports are different! So, to make it work, you not only need to allow all CORS, which is not possible in my case because our servers admin won't let that happen, but you also need to remove a check in the Angular interceptor (authorize.interceptor.ts) that checks that the request bears the same origin as the window.location.host. This, to me, feels like removing a security check.

So I feel my solution lies with that port story. My colleague recreated a project from scratch, to compare, and his app launches the proxy on the same port as the API! What's going on? I don't want to start from scratch. And I want to understand if I can control the port the proxy is launched on. I tried simply editing the number 44484 everywhere it was in the code to 44384 but the command would just loop forever.

I don't understand and I can't find an answer online, like I'm the only developer not getting this. Please any advice. Thanks guys.

0 Answers
Related