Dialogflow API突然开始返回CORS错误

时间:2018-10-13 08:57:41

标签: dialogflow

Dialogflow已正确设置,并且可以正常运行约一个月。今天,它突然开始返回此错误:

Failed to load https://api.dialogflow.com/v1/query?lang=en&query=hi&sessionId=bgknzzf1q: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4001' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

我该如何解决?

1 个答案:

答案 0 :(得分:0)

解决此临时问题的一种方法是使用代理作为临时解决方案:https://www.npmjs.com/package/cors-anywhere

示例:

ApiAiConstants.DEFAULT_BASE_URL = 
    "https://cors-anywhere.herokuapp.com/https://api.api.ai/v1/";

缺点是授权标头和其他信息会在传递过程中被拦截。参见https://github.com/dialogflow/dialogflow-javascript-client/issues/102