# Facing CORS error when I am trying to call QA graphql api's from the localhost nextjs application

**URL:** <https://community.apollographql.com/t/facing-cors-error-when-i-am-trying-to-call-qa-graphql-apis-from-the-localhost-nextjs-application/6877>\
**Category:** Server\
**Tags:** server\
**Created:** [October 24, 2023, 5:21pm UTC](https://community.apollographql.com/t/facing-cors-error-when-i-am-trying-to-call-qa-graphql-apis-from-the-localhost-nextjs-application/6877 "2023-10-24T17:21:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishnu](https://avatars.discourse-cdn.com/v4/letter/v/258eb7/32.png) [@vishnu](https://community.apollographql.com/u/vishnu)\
**Post date:** [October 24, 2023, 5:21pm UTC](https://community.apollographql.com/t/facing-cors-error-when-i-am-trying-to-call-qa-graphql-apis-from-the-localhost-nextjs-application/6877/1 "2023-10-24T17:21:45Z")

</div>

My Apollo client looks like this and the link refers to qa domain url. I tried multiple options but nothing worked could someone suggest me on this.

const client = new ApolloClient({  
link: httpLink, // qa domain graphql url  
cache: new InMemoryCache(),  
defaultOptions: defaultOptions,  
headers: {  
“Content-Type”: ‘application/json’,  
“Access-Control-Allow-Origin”: ‘\*’,  
“Access-Control-Allow-Credentials”: “true”  
},  
});

and from server side my code looks like below.

import cors from ‘cors’  
import express from ‘express’;  
import { ApolloServer } from ‘apollo-server-express’;  
import { ApolloServerPluginDrainHttpServer } from “apollo-server-core”;  
import http from “http”;

async function startApolloServer(schema: any, resolvers: any) {  
const app = express();  
app.use(cors({origin:‘\*’}) )

const httpServer = http.createServer(app);  
const server = new ApolloServer({  
typeDefs: schema,  
resolvers,  
//tell Express to attach GraphQL functionality to the server  
plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],  
context: async ({ req }) =\> ({ dataSource })  
}) ;  
await server.start(); //start the GraphQL server.  
server.applyMiddleware({ app });  
await new Promise((resolve) =\>  
httpServer.listen({ port: 4000 }, resolve) //run the server on port 4000  
);  
console.log(`Server ready at http://localhost:4000${server.graphqlPath}`);  
}  
//in the end, run the server and pass in our Schema and Resolver.  
startApolloServer(typeDefs, resolvers);

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:48pm UTC](https://community.apollographql.com/t/facing-cors-error-when-i-am-trying-to-call-qa-graphql-apis-from-the-localhost-nextjs-application/6877/2 "2025-02-06T20:48:05Z")

</div>

Archived on February 6, 2025, 8:48pm UTC


