Access-Control-Allow-Origin (Laravel & Vue) CORS CORB error on localhost - TagMerge
5Access-Control-Allow-Origin (Laravel & Vue) CORS CORB error on localhostAccess-Control-Allow-Origin (Laravel & Vue) CORS CORB error on localhost

Access-Control-Allow-Origin (Laravel & Vue) CORS CORB error on localhost

Asked 1 years ago
7
5 answers

As you have no access in API's source code so there is nothing to do with .htaccess or adding 'Access-Control-Allow-Origin': '*', in script. But still you can eradicate this error by opening chrome browser with disabled security mode

In windows run CMD (press together windows button and R key from keyboard. Then type cmd in box and enter).

Secondly go to C drive (in CLI) or where your chrome installed (using cd command) then run following command

“Program Files (x86)\Google\Chrome\Application\chrome.exe” –-allow-file-access-from-files --disable-web-security --user-data-dir --disable-features=CrossSiteDocumentBlockingIfIsolating

It will open your browser in disabled web security mode. Once you done it you can test now with this kind of CORS or CORB error.

note: before running this command make sure there are no chrome are opened already.

Program Files (x86)\Google\Chrome\Application\chrome.exe this should be your chrome installed path

However after opening browser it will show as below, dont panic & dont close this message. if you close this message it will again through this CORS or CORB error enter image description here

Source: link

1

Changing

'Content-Type': 'application/json',

to the following will solve the problem:

'Content-Type': 'text/html; charset=UTF-8',

Source: link

-1

Update config/cors.php

   'supportsCredentials' => false,
   'allowedOrigins' => ['*'],
   'allowedHeaders' => ['*'],
   'allowedMethods' => ['*'], // ex: ['GET', 'POST', 'PUT',  'DELETE']
   'exposedHeaders' => ['*'],
   'maxAge' => 0,

   then run
   php artisan config:cache 
   command i think it will help you

Source: link

0

Step 1:
composer require barryvdh/laravel-cors
You also need to add Cors\ServiceProvider to your config/app.php providers array:
FruitCake\Cors\CorsServiceProvider::class,
For global uses:
protected $middleware = [
    // ...
    \Fruitcake\Cors\HandleCors::class,
];
For middleware uses:
protected $middlewareGroups = [
   'web' => [
       // ...
   ],

   'api' => [
        // ...
        \Fruitcake\Cors\HandleCors::class,
    ],
];
Once your installation completed run below command to publish the vendor files.
php artisan vendor:publish --provider="Fruitcake\Cors\ServiceProvider"

Source: link

0

chore: add `.editorconfig` file (#546)
This commit adds `.editorconfig` file.

For more information, please check https://editorconfig.org/
Require the fruitcake/laravel-cors package in your composer.json and update your dependencies:
composer require fruitcake/laravel-cors
If you get a conflict, this could be because an older version of barryvdh/laravel-cors or fruitcake/laravel-cors is installed. Remove the conflicting package first, then try install again:
composer remove barryvdh/laravel-cors fruitcake/laravel-cors
composer require fruitcake/laravel-cors
To allow CORS for all your routes, add the HandleCors middleware at the top of the $middleware property of app/Http/Kernel.php class:
protected $middleware = [
  \Fruitcake\Cors\HandleCors::class,
    // ...
];
Now update the config to define the paths you want to run the CORS service on, (see Configuration below):
'paths' => ['api/*'],

Source: link

Recent Questions on laravel

    Programming Languages