title: CORS error on POST, PUT, & DELETE request, but GET working fine
body: <p>I'm currently building an application using MERN stack and I'm having problems accessing my REST api. It's able to fetch data using get request, but writing data seems to fail.</p>
  
  <p>I have this code block before declaring my routes:</p>
  
  <pre><code>app.use(function(req, res, next) {
      res.header('Access-Control-Allow-Origin', 'https://staging.domain.io');
      res.header('Access-Control-Allow-Methods', 'GET, OPTIONS, PUT, POST, DELETE');
      res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
      res.header('Access-Control-Allow-Credentials', true);
      next();
  });
  </code></pre>
  
  <p>I'm using axios in the front end to make those api calls and have withCredentials attribute set to true</p>
  
  <h2>Some things to note that might be of use:</h2>
  
  <p>I'm sharing my cookies within my domains and subdomains by using cookie-session (declared BEFORE CORS configuration (above code)</p>
  
  <pre><code>app.use(
    session({
      maxAge: 24 * 60 * 60 * 1000,
      keys: [process.env.SESSION_ENCRYPTION],
      domain: 'domain.io',
      signed: true,
      httpOnly: false,
      secure: false
    }));
  </code></pre>
  
  <p>This only failed when I deployed to GCP, it was working fine on localhost.</p>
  
  <h2>What I've tried so far:</h2>
  
  <p>Used express cors middleware package and configured it as follows:</p>
  
  <pre><code>app.use(
    cors({
      origin: 'https://staging.domain.io/',
      credentials: true
    })
  );
  app.options(
    "*",
    cors({
      origin: 'https://staging.domain.io/',
      credentials: true
    })
  );
  </code></pre>
  
  <p>Seems like this code is not changing the behavior at all since there was nothing different regardless if that code is placed. However, if I keep that code and remove the code at the very top, the whole api fails (even GET requests).</p>
  
  <p>So now I'm kinda stuck as to how to go about this problem. Any suggestions?</p>
  
  <p>Thanks!</p>