-1

I'm witnessing something that I really don't like and that I think is the root of my issue :

chrome console

Access to XMLHttpRequest at 'https://localhost:5001/calls/api/Auth/register' (redirected from 'http://localhost:4200/calls/api/Auth/register') from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Http failure response for /calls/api/Auth/register: 0 Unknown Error
POST https://localhost:5001/calls/api/Auth/register net::ERR_FAILED

what worries me here is the 5001. here's my "proxy.config.json" :

{
  "/calls/*": {
    "target": "http://localhost:5000",
    "secure": false,
    "logLevel": "debug"
  }
}

which I load in "angular.json" thanks to the "proxyConfig": setting (angular docs) :

"proxyConfig": "src/proxy.conf.json"

I can tell this functioned because when I serve the app I get :

Generating browser application bundles...[HPM] Proxy created: /calls  ->  http://localhost:5000

I call my api like so :

register(email: string, password: string) {
  return this.http.post('/calls/api/Auth/register',  {
    params: {
      email: "vb@gmail.com",
      password: "ButtsMacgee311",
      userName: "newUser"
    },
    observe: 'response'
  }).subscribe(
    data => console.log(data),
    error => console.error(error.message)
 )
}

So obviously nowhere in my entire project is there a mention of a "5001" what part of angular is incrementing to "5001" and how do I stop it from doing that?

And if that's not the real issue then what am I doing wrong?

For context this is a personal project run on my home computer so I don't have to deal with any corporate proxy, also I do have access to the backend source code and I am running my own version locally (run from console), it's in C# and I can access the swagger and test APIs under : http://localhost:5000/api-docs/index.html

tatsu
  • 2,316
  • 7
  • 43
  • 87

1 Answers1

0

CORS errors are confusing. But I think this might be your API not accepting your calls from Front-end. I see that you are using C# for your back-end. Double-check that it accepts calls from your localhost (or *, if you're not bothered about security). I know that ASP.NET can sometimes be a pain with CORS.

Gideon Botha
  • 126
  • 10