more fixes
This commit is contained in:
34
app/Http/Middleware/ConditionalCors.php
Normal file
34
app/Http/Middleware/ConditionalCors.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Middleware\HandleCors as BaseHandleCors;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ConditionalCors
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$paths = config('cors.paths', null);
|
||||
|
||||
// If paths are empty the CORS config intentionally disables CORS.
|
||||
if (is_array($paths) && count($paths) === 0) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Fallback to env if config wasn't populated for some reason.
|
||||
$enabled = env('CP_ENABLE_CORS', true);
|
||||
|
||||
if (! $enabled) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$handler = app(BaseHandleCors::class);
|
||||
|
||||
return $handler->handle($request, $next);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user