dialogflow / dialogflow-javascript-client

JavaScript Web SDK for Dialogflow
Apache License 2.0
412 stars 173 forks source link

Angular 6 CORS issue #86

Open Jbz797 opened 6 years ago

Jbz797 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Did you solve ?

m00zi commented 6 years ago

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

Franweb79 commented 6 years ago

Same problem here

Primtek commented 6 years ago

also same here :( ..

mariossavva commented 5 years ago

same here... any progress on this issue?

zegyedi commented 5 years ago

same here :(

Leezio commented 5 years ago

also same here ...

byronglendon commented 5 years ago

same here... any suggestions?

jncalderon commented 5 years ago

I also need help! :(

m00zi commented 5 years ago

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 commented 5 years ago

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

m00zi commented 5 years ago

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

jncalderon commented 5 years ago

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 notifications@github.com 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 .

harshinipenigalapati commented 5 years ago

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 commented 5 years ago

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

Maroof-Khan commented 4 years ago

Also facing same issue