Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12261

Apollo Server v4 throws Cors issue

$
0
0

I am getting the typical CORS issue while accessing my backend

Here is my backend code

const app = express();const httpServer = http.createServer(app);const server = new ApolloServer({  typeDefs,  resolvers,  plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],});await server.start();app.use("/graphql",  cors({    origin: "http://localhost:3000/",    credentials: true,  }),  express.json(),  expressMiddleware(server));await new Promise((resolve) => httpServer.listen({ port: 4000 }, resolve));console.log("Server started at ", 4000);

Here is my frontend code

First way:

const client = new ApolloClient({    cache: new InMemoryCache(),    link: new HttpLink({      uri: "https:/localhost:4000/graphql",    }),  });

Second way

const client = new ApolloClient({    uri: "https:/localhost:4000/graphql",    cache: new InMemoryCache(),  });

Tried both way but still the issue persists


Viewing all articles
Browse latest Browse all 12261

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>