Open ghost opened 3 years ago
I have same problem. If you upgrade Laravel version, then it is over.
I was able to solve the problem in this way, in my case it was due to a configuration that needed the web.config file, I had to add the following
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="*" />
<add name="Access-Control-Allow-Headers" value="Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization" />
</customHeaders>
</httpProtocol>
And my file stayed like this
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="*" />
<add name="Access-Control-Allow-Headers" value="Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
This alone still gives a Cors error, but it is due to the implementation of the fruitcake that the laravel version already brings, it is only necessary to comment that class in the kernel
protected $middleware = [
\App\Http\Middleware\TrustProxies::class,
// \Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class
];
Now with this it works fine
I have an Api Rest with Laravel 8 and a front-end with VueJS, everything works fine from postman, but when making requests from Vue it gives cors error.
I also tried creating a Cors middleware that contains the following:
It also keeps throwing cors error, the library that includes the laravel version is: "fruitcake / laravel-cors": "^ 2.0", but this still doesn't work.
How could I fix my cors error?