dialogflow-javascript-client icon indicating copy to clipboard operation
dialogflow-javascript-client copied to clipboard

Angular 6 CORS issue

Open Jbz797 opened this issue 6 years ago • 18 comments

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

Jbz797 avatar May 15 '18 14:05 Jbz797

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?

Parez avatar May 23 '18 19:05 Parez

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

xmlking avatar Jun 01 '18 01:06 xmlking

Did you solve ?

gbrcmg avatar Jun 08 '18 20:06 gbrcmg

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,

https://github.com/nodejs/help/issues/1325

m00zi avatar Jun 09 '18 09:06 m00zi

Same problem here

Franweb79 avatar Aug 31 '18 17:08 Franweb79

also same here :( ..

Primtek avatar Sep 05 '18 04:09 Primtek

same here... any progress on this issue?

mariossavva avatar Oct 08 '18 18:10 mariossavva

same here :(

zegyedi avatar Oct 16 '18 20:10 zegyedi

also same here ...

Leezio avatar Nov 19 '18 09:11 Leezio

same here... any suggestions?

byronglendon avatar Nov 20 '18 00:11 byronglendon

I also need help! :(

jncalderon avatar Nov 21 '18 00:11 jncalderon

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.

m00zi avatar Nov 21 '18 04:11 m00zi

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

Leezio avatar Nov 21 '18 08:11 Leezio

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

m00zi avatar Nov 21 '18 09:11 m00zi

hi but dont work for me un dev, I always have a response OPTIONS, my api is on Homestead, laravel with passport auth Nelson Calderón My Numbers: +506 8789-7230

On Wed, Nov 21, 2018 at 3:11 AM m00zi [email protected] wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dialogflow/dialogflow-javascript-client/issues/86#issuecomment-440589958, or mute the thread https://github.com/notifications/unsubscribe-auth/AOowzamKlITPWxisKgnuMXqFYX8KCQvWks5uxRipgaJpZM4T_nPZ .

jncalderon avatar Nov 21 '18 14:11 jncalderon

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.

harshinipenigalapati avatar May 30 '19 09:05 harshinipenigalapati

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

ankit21ks avatar Jun 02 '19 07:06 ankit21ks

Also facing same issue

Maroof-Khan avatar Sep 21 '19 11:09 Maroof-Khan