kovaxxx's avatar

CORS issue on static assets

Hi,

I got CORS issue on my project:

Access to script at 'hxxps://app.clickcraft.hu/assets/js/craft/craft.js' from origin 'hxxps://www.diamondnails.hu' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

my cors config is:

'paths' => ['*'],

'allowed_methods' => ['*'],

'allowed_origins' => ['*'],

'allowed_origins_patterns' => ['*'],

'allowed_headers' => ['*'],

'exposed_headers' => [],

'supportedContentTypes' => [
    'application/json',
    'text/html',
    'text/plain',
    'application/javascript',
    'application/x-javascript',
    'text/javascript',
    'text/css'
],

'max_age' => 0,

'supports_credentials' => false,

But not working.

I also tried to modify the public/.htaccess:

<IfModule mod_headers.c> <FilesMatch "\.(js|css|bmp|cur|gif|ico|jpe?g|png|svgz?|webp|pdf|eot|otf|tt[cf]|woff2?)$"> Header set Access-Control-Allow-Origin "*" env=IS_CORS Header set Cross-Origin-Resource-Policy 'cross-origin' </FilesMatch> </IfModule>

but also not working.

Any other API requests is OK. How can I enable CORS to static assets?

0 likes
1 reply
kovaxxx's avatar
kovaxxx
OP
Best Answer
Level 1

So the problem is: When scripts are loaded with type="module", browsers now enforce CORS rules."

And the the solution:

hxxps://masteringlaravel.io/daily/2024-03-07-something-to-know-if-serving-scripts-for-other-sites hxxps://masteringlaravel.io/daily/2024-03-08-how-to-set-cors-headers-for-built-assets?utm_source=laravelnews&utm_medium=link&utm_campaign=laravelnews

Please or to participate in this conversation.