How to fix No 'Access-Control-Allow-Origin' header is present on the requested resource?

0

Like the title says.

I am using Strapi v. 3.6.10.

Today I am getting the error that says: “Access to XMLHttpRequest at “server_url” from origin “frontend_url” has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”

Until yesterday everything was working fine and here’s the middleware.js configuration up till yesterday:

module.exports = {
  settings: {
    parser: {
      textLimit: '10mb',
      formLimit: '10mb', // modify here limit of the form body
      jsonLimit: '10mb', // modify here limit of the JSON body
      formidable: {
        maxFileSize: 100 * 1024 * 1024, // multipart data, modify here limit of uploaded file size
      },
    },
  },
};

Today when it stopped working. I don’t know why, but then I made these changes to middleware.js but still it doesn’t work:

module.exports = {
  settings: {
    cors: {
      enabled: true,
      origin: ['*'],
      headers: [
        'Content-Type',
        'Authorization',
        'X-Frame-Options',
        'Origin',
        'Accept',
      ],
    },
    parser: {
      textLimit: '10mb',
      formLimit: '10mb', // modify here limit of the form body
      jsonLimit: '10mb', // modify here limit of the JSON body
      formidable: {
        maxFileSize: 100 * 1024 * 1024, // multipart data, modify here limit of uploaded file size
      },
    },
  },
};

None of the above configurations work. I have been trying to fix it for hours but no luck…

Your help would be greatly appreciated!