1

I am using dot-net for my back-end and angular for my front-end. Until now I used to create both front and back-end separately. Of course I should take care of Cross-origin issue, so the front-end can communicate with back-end. Lately I used the (ASP.Net Core With Angular) template, and instead of separately creating my angular project. I created it within my back-end solution as a project. In this template you see that Visual Studio create an Angular project for you with some extra files and provide you directly a Controller folder. In this template project, you see a proxy in a file named: (proxy.conf.js) and you can call your back-end without Cross-origin issue. However I read that this is only for local tests. It use a server and this saver is based on the Webpack dev server. I read it from this article: https://juristr.com/blog/2016/11/configure-proxy-api-angular-cli/

I am intended to host my solution later in Azure in a Webapp.

My questions: 1- Which approach is the better one, creating a separate Angular project and host it separately or using the (ASP.Net Core With Angular) template from Visual Studio? and why?

2- Assume I use the (ASP.Net Core With Angular) template, in this case the proxy is only for local test, right? If yes, do you think it is a good idea to remove the proxy and for local test as well as later in cloud use Cross-origin policy in my back-end?

Hamid
  • 43
  • 6

1 Answers1

0

using the proxy is good for both local testing and production

but for production you should consider more performant proxy like nginx (which can also serve the Angular project)

CORS will make your website slow as the browser will need to make pre-flight request before each request which will somehow double the time to get the data from the API

Robert
  • 2,342
  • 2
  • 24
  • 41
  • First tnx for your answer. Do you have some tutorials or references how I can use the nginx with Angular? And about the first question is it a good idea to use Visual Studio Angular template? – Hamid Mar 10 '23 at 22:28
  • the comment yesterday was "First tnx for your answer", I thought you would add another comment but never got the notification and I just remembered to check what's going on to find you edited the original comment haha – Robert Mar 11 '23 at 23:11
  • for nginx with angular please read here https://angular.io/guide/deployment#server-configuration search for the word nginx to see it, but it's not much – Robert Mar 11 '23 at 23:12
  • https://dev.to/ritesh4u/deploy-angular-application-with-nginx-and-docker-3jf6#nginxconf here is another example – Robert Mar 11 '23 at 23:15
  • I'd prefer to keep my angular code away from my C# ones since they are not related, and use visual studio for the C# part and vs code or webstorm for the angular – Robert Mar 11 '23 at 23:17