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

Access-Control-Allow-Origin issue #103

Open
latheesh08 opened this issue Oct 13, 2018 · 6 comments
Open

Access-Control-Allow-Origin issue #103

latheesh08 opened this issue Oct 13, 2018 · 6 comments

Comments

@latheesh08
Copy link

Failed to load https://api.api.ai/v1/query?v=20150910: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

Still having same issue please respond as fast as possible.
if anybody have solutions please ping me,

thank you

@latheesh08
Copy link
Author

change apiai.js
this.uri = this.apiAiClient.getApiBaseUrl() + "query?v=" + this.apiAiClient.getApiVersion();
to
this.uri = "https://cors-anywhere.herokuapp.com/" + this.apiAiClient.getApiBaseUrl() + "query?v=" + this.apiAiClient.getApiVersion();

this worked me

@TenTaeTme
Copy link

not sure using apps like https://cors-anywhere.herokuapp.com/ good solution for this issue.

@fdavies93
Copy link

See here: you can install cors-anywhere on a server you own.

#102 (comment)

@ATakaSKY
Copy link

ATakaSKY commented Oct 15, 2018

I am also getting the same error. Plugin worked fine 3 days back but now this CORS issue has started to pop up. @fdavies93 - can you please tell how to include the cors anywhere in my nodejs code. THis is my node code:

var express = require('express');
var bodyParser = require('body-parser');
var request = require('request');
var cors_proxy = require('cors-anywhere');

var app = express();

var port = process.env.PORT || 3000;
var ip = process.env.IP || '127.0.0.1';
var host = process.env.HOST || '0.0.0.0';

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header(
    'Access-Control-Allow-Headers',
    'Origin, X-Requested-With, Content-Type, Accept, Authorization'
  );
  res.header(
    'Access-Control-Allow-Methods',
    'GET, POST, PATCH, DELETE, OPTIONS'
  );
  next();
});

app.post('/', function(req, res) {
  console.log('REq body', req.body);
  console.log('Response ID', req.body.responseId);
  console.log('Action', req.body.queryResult.action);

let response = {
      text:
        'hey there',
      policies: ['abc', 'def'],
      context: 'report_claim_context'
    };

    res.json({
      payload: response
    });
}

app.listen(port,ip);

@fdavies93
Copy link

I am also getting the same error. Plugin worked fine 3 days back but now this CORS issue has started to pop up. @fdavies93 - can you please tell how to include the cors anywhere in my nodejs code.

Maybe a spot of confusion here -- CORS anywhere is a proxy server which you'd have to run as a separate app, then route requests to api.api.ai through. Not sure about your setup but in a containerised environment this isn't too bad.

I did this by hunting down the URL variables in dialogflow-javascript-client, changing them to point at [proxy url]/https://api.api.ai/, then rebuilding the library for my apps. A bit of a pain but worked and was a quick fix until Google sort it properly.

I am curious why you're suddenly having CORS issues though, as your setup doesn't seem to touch the Dialogflow servers. Possibly you're not handling the OPTIONS call which Chrome (and maybe other browsers) sends before handling POST responses?

@husnejahan
Copy link

"Access to XMLHttpRequest at 'https://api.api.ai/v1/query?v=20150910' from origin 'https://.......com' has been blocked by CORS policy: Request header field x-usertoken is not allowed by Access-Control-Allow-Headers in preflight response."

I am getting this error, I allowed cord although

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

5 participants