Loopback 4 intermittent CORS issue

Viewed 21

I have a LB4 application running on Heroku. And 80% of the times it is giving me a CORS error.

Access to XMLHttpRequest at 'https://aaaa' from origin 'https://bbbbb' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

The funny part is, sometimes the request DOES work and when it does it will work for a while. then afterwards it will start failing again.

In my index.ts I have set my CORS to allow everything but strangly this doesn`t change anything.

  // Run the application
  const config = {
    rest: {
      port: +(process.env.PORT ?? 3000),
      host: process.env.HOST,
      // The `gracePeriodForClose` provides a graceful close for http/https
      // servers with keep-alive clients. The default value is `Infinity`
      // (don't force-close). If you want to immediately destroy all sockets
      // upon stop, set its value to `0`.
      // See https://www.npmjs.com/package/stoppable
      gracePeriodForClose: 5000, // 5 seconds
      openApiSpec: {
        // useful when used with OpenAPI-to-GraphQL to locate your application
        setServersFromRequest: true
      },
      cors: {
        origin: '*'
      }
    },
  };
  main(config).catch(err => {
    console.error('Cannot start the application.', err);
    process.exit(1);
  });
}```


// Anyone have any ideas on how to solve this ?
0 Answers
Related