Answer the question
In order to leave comments, you need to log in
Why did the CORS problem appear?
Hi all! Such a disaster. Initially installed CORS middleware. and added headers to htaccess. Everything worked on a "normal" controller, so to speak. After I decided to optimize and created a resource controller. On LAN, everything worked out the rules, and after, when the transfer to the host, there was a problem with CORS. I can't send a POST request while GET works fine..
<?php
namespace App\Http\Middleware;
use Closure;
class Cors {
public function handle($request, Closure $next)
{
return $next($request)
->header('Access-Control-Allow-Origin', 'http://app.bezraboty.by')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
}
}
<IfModule mod_rewrite.c>
RewriteEngine On
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Answer the question
In order to leave comments, you need to log in
Everything worked fine locally
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question