Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular 6 CORS issue #86

Open
Jbz797 opened this issue May 15, 2018 · 18 comments
Open

Angular 6 CORS issue #86

Jbz797 opened this issue May 15, 2018 · 18 comments

Comments

@Jbz797
Copy link

Jbz797 commented May 15, 2018

After upgrading to Angular 6 I have this issue :

Failed to load https://api.api.ai/v1/query?*** Method undefined is not allowed by Access-Control-Allow-Methods in preflight response.

Indeed the "access-control-request-method" on the OPTION request is undefined :

capture d ecran 2018-05-15 a 15 59 59

@Parez
Copy link

Parez commented May 23, 2018

Have an exactly same problem. In dev build everything works fine. But got the same error when building with --prod flag. Have you managed to find a solution yet?

@xmlking
Copy link

xmlking commented Jun 1, 2018

It was working for me before with angular 5.
Recently I migrated to angular 6 and now seeing CORS issue.
Not user if google did change something on the server side or angular6 causing this issue

@gbrcmg
Copy link

gbrcmg commented Jun 8, 2018

Did you solve ?

@m00zi
Copy link

m00zi commented Jun 9, 2018

I have the same problem, by the way for me it is working when the server is running on http, but when I am running the server on https, I am not getting any response from server, 0, which mean cors issue,

nodejs/help#1325

@Franweb79
Copy link

Same problem here

@Primtek
Copy link

Primtek commented Sep 5, 2018

also same here :( ..

@mariossavva
Copy link

same here... any progress on this issue?

@zegyedi
Copy link

zegyedi commented Oct 16, 2018

same here :(

@Leezio
Copy link

Leezio commented Nov 19, 2018

also same here ...

@byronglendon
Copy link

same here...
any suggestions?

@jncalderon
Copy link

I also need help! :(

@m00zi
Copy link

m00zi commented Nov 21, 2018

you could use proxy to solve this issue:
under root directory of your angular project (in the same level of package.json create new file name it proxy.json add the below content so all your api calls toward backend will be done through proxy and no CORS issue anymore, by the way using this way for production also is secure than call backend directly :
lets assume you are serving API under /api on your backend server so :

STEP1:

{
    "/api": {
        "target": "https://127.0.0.1:3000",
        "secure": "false",
        "changeOrigin": true
    }
}

and in your angular service file you dont need to add full url in order to get or post:

STEP 2:

getEmps() {
    return this.http.get('/api/emps')
  }

STEP 3:

edit your package.json file :

"start": "ng serve --proxy-config proxy.json --ssl true",

Done.

@Leezio
Copy link

Leezio commented Nov 21, 2018

Thks, but it works only for dev not prod environment !

@m00zi
Copy link

m00zi commented Nov 21, 2018

for production you can use nginx to do the proxy function for you, I have already implemented on production and its working fine.

@jncalderon
Copy link

jncalderon commented Nov 21, 2018 via email

@harshinipenigalapati
Copy link

hi,for me cors issue is solved,but in my case for api i need to call only localhost no need to use port,so in that case for api it is taking localhost:4200 with api path.so that am not getting data from api.please any one have idea.

@ankit21ks
Copy link

You can follow this tutorials to solve this issue
http://www.codeyourthought.com/angular/proxy-to-make-http-call-in-angular/

@Maroof-Khan
Copy link

Also facing same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests