title: cors error: No 'Access-Control-Allow-Origin' header apollo-server-express
body: <p>I create a project using apollo express server, apollo client 3.0. I get a cors error on the image upload side. my server side is like this.</p>
  <p>Note : It loads images that are like 1 kb. but every image with a high kb error gives cors errors. sometimes uploads half the picture.</p>
  <p><em><strong>images are uploaded to s3.</strong></em></p>
  <p>Note 2: <strong>localhost also works with no errors.</strong></p>
  <p>I am using client side apollo-upload-client for upload. There is no cors setting on the client side.</p>
  <p>I tried origin on url for cors option but it still didn't work.</p>
  <pre><code>const http = require(&quot;http&quot;);
  const express = require(&quot;express&quot;);
  require(&quot;dotenv&quot;).config();
  const mongoose = require(&quot;mongoose&quot;);
  const jwt = require(&quot;jsonwebtoken&quot;);
  const { PubSub } = require(&quot;apollo-server&quot;);
  const { ApolloServer } = require(&quot;apollo-server-express&quot;);
  const { importSchema } = require(&quot;graphql-import&quot;);
  const { GraphQLUpload, graphqlUploadExpress } = require(&quot;graphql-upload&quot;);
  const GraphQLJSON = require(&quot;graphql-type-json&quot;);
  const cors        = require(&quot;cors&quot;);
  const bodyParser = require('body-parser')
  
  // RESOLVERS
  const resolvers = require(&quot;./graphql/resolvers/index&quot;);
  
  const resolveFunctions = {
    JSON: GraphQLJSON,
    Upload: GraphQLUpload
  };
  
  // models
  
  const Admin = require(&quot;./models/Admin&quot;);
  const Customer = require(&quot;./models/Customers&quot;);
  
  const pubsub = new PubSub();
  const app = express();
  
  var corsOptions = {
    origin: '*',
    credentials: true
  };
  
  // SCHEMA
  const server = new ApolloServer({
    cors: corsOptions,
    typeDefs: importSchema(&quot;./graphql/schema.graphql&quot;),
    resolvers,
    resolveFunctions,
    context: ({ req }) =&gt; ({
      Admin,
      Customer,
      pubsub,
      activeAdmin: req ? req.activeAdmin : null
    })
  });
  
  
  // DB
  mongoose
    .connect(process.env.MONGODB_URI, {
      useNewUrlParser: true,
      useUnifiedTopology: true
    })
    .then(() =&gt; console.log(&quot;Connected to MongoDB&quot;))
    .catch(e =&gt; console.log(e));
  
  
  
  app.use(async (req, res, next) =&gt; {
    graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 });
    const token = req.headers[&quot;authorization&quot;];
    if (token &amp;&amp; token !== &quot;null&quot;) {
      try {
        const activeAdmin = await jwt.verify(token, process.env.SECRET_KEY);
        req.activeAdmin = activeAdmin;
      } catch (e) {
        console.log(&quot;ERROR&quot;, e);
      }
    }
    next();
  });
  
  server.applyMiddleware({ app, cors: corsOptions});
  const httpServer = http.createServer(app);
  server.installSubscriptionHandlers(httpServer);
  
  httpServer.listen(process.env.PORT || 4004, () =&gt;
    console.log(
      ` Server ready at http://localhost:4004${server.graphqlPath}`
    )
  );
  </code></pre>
  <p>when I try to upload an image, error;</p>
  <pre><code>Access to fetch at 'https://adminurl.herokuapp.com/graphql' from origin 'https://clienturl' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
  </code></pre>
  <p>I am using heroku, heroku error</p>
  <pre><code>2020-11-08T02:51:30.233151+00:00 heroku[router]: sock=backend at=error code=H18 desc=&quot;Server Request Interrupted&quot; method=POST path=&quot;/graphql&quot; host=****domain**** request_id=d4db3170-15c4-41d5-81cf-83b42552d90a fwd=&quot;194.54.28.40&quot; dyno=web.1 connect=1ms service=340ms status=503 bytes=386 protocol=https
  </code></pre>