[Vuejs]-'http://localhost:8080' has been blocked by CORS policy Laravel8

-1👍

Html to canvas uses element in DOM that’s why it’s requiring a cors from your public folder but laravel does not support that, it only supports cors with api. You need to change your config file.

If you are using nginx use this:

location /storage/ {
    add_header 'Access-Control-Allow-Origin' '*';
}

Apache:

<IfModule mod_headers.c>
    <FilesMatch "\.(bmp|cur|gif|ico|jpe?g|png|svgz?|webp|pdf)$">
        Header set Access-Control-Allow-Origin "*"
    </FilesMatch>
</IfModule>

Take note that you need to change the Access-Control-Allow-Origin when deploying to prod to only accept the valid server origin.

Leave a comment