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

CORS localhost loading props but calling ip not working #529

Closed
cristiandley opened this issue Aug 11, 2016 · 6 comments
Closed

CORS localhost loading props but calling ip not working #529

cristiandley opened this issue Aug 11, 2016 · 6 comments

Comments

@cristiandley
Copy link

Before upgrading Apollo/Meteor i could access my app from localhost:3000 or from other computer using my IP or from my computer using my own private IP. Now i can see the React dom but is not loading any data.

Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
Fetch API cannot load http://localhost:3000/graphql. Response to preflight request doesn't pass access 

control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 

'http://my_beutiful_ip:3000' is therefore not allowed access. The response had HTTP status code 405. 

If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource 

with CORS disabled.

i can access my_ip:3000/graphql

is there any new configuration im missing ?

Thanks !

@cristiandley cristiandley changed the title localhost loading props but calling ip not working CORS localhost loading props but calling ip not working Aug 11, 2016
@stubailo
Copy link
Contributor

Have you tried to CORS options as specified here? http://docs.apollostack.com/apollo-client/index.html#corsSupport

Otherwise, it might be that your server doesn't accept CORS requests. How have you hooked up GraphQL to your web server?

@cristiandley
Copy link
Author

@stubailo i tried this:

import { createApolloServer } from 'meteor/apollo';
//import cors from 'cors';

import schema from '../imports/api/schema';
import resolvers from '../imports/api/resolvers';


createApolloServer({
  graphiql: true,
  pretty: true,
  schema,
  resolvers,
});

//graphQLServer.use('*', cors());

what im trying to do is to get is graphQLServer... that is in the createApolloServer, but i couldn't import it.

@stubailo
Copy link
Contributor

Hmm, I think this definitely should be in meteor-integration. I don't think it has anything to do with apollo client.

One option is to simply not use the meteor/apollo package, and just attach the graphQLServer to Meteor directly, as @jangerhofer mentioned on the other thread.

@tgoldenberg
Copy link

tgoldenberg commented Oct 2, 2016

@stubailo The CORS support link is broken. Any help with this? I am using all npm packages in a Meteor app but getting the same error. Server is running fine at localhost:8080/graphql

@vladinator1000
Copy link

vladinator1000 commented Dec 2, 2016

Having the same problem, would love for the docs to have an example of how to enable cors. In the meantime, this thread fixed my issue:

import cors from 'cors';

//FIXES CORS ERROR
const whitelist = [
    // Allow domains here
    'http://localhost:3000',
];
const corsOptions = {
    origin(origin, callback){
        const originIsWhitelisted = whitelist.indexOf(origin) !== -1;
        callback(null, originIsWhitelisted);
    },
    credentials: true
};
graphQLServer.use(cors(corsOptions));

@Rogant
Copy link

Rogant commented Nov 12, 2017

I have the same bug with Express and React

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants