Mobile only CORS Error: Origin is not allowed by Access-Control-Allow-Origin In Node.js

Viewed 1128

I've set up a Node.js (TypeScript hosted on Google Cloud Platform [GCP]) app for CORS but I'm still getting errors (Origin is not allowed by Access-Control-Allow-Origin) on mobile--desktop works fine.

I've searched but there are so many questions about getting this set up in general, I can't find why it specifically isn't working for mobile.

    this.app.use(cors()); 
    this.app.options('*', cors());

...

    router.use(function(req, res, next) {
          res.header('Content-Type', 'application/json');
          res.setHeader('Access-Control-Allow-Origin', '*');
          res.setHeader('Access-Control-Allow-Methods', 'DELETE,GET,OPTIONS,PATCH,POST');
          res.setHeader('Access-Control-Allow-Headers', 'Origin, Accept, Authorization, Content-Type, X-Requested-With, Access-Control-Allow-Headers, Access-Control-Request-Method, Access-Control-Request-Headers');
          next();
        });

BTW The errors don't appear in the console until a few minutes after the page has loaded. (I've removed the URLs which are valid.)

"XMLHttpRequest cannot load due to access control checks."

"Failed to load resource: Origin is not allowed by Access-Control-Allow-Origin."

1 Answers

The issue was missing data in the DB, so the Node endpoint was not returning properly. The errors had nothing to do with the problem.

Related