From 1f61601e053ad6cfbae38b5677747716fb782530 Mon Sep 17 00:00:00 2001 From: F4ilji Date: Fri, 9 Jan 2026 19:07:51 +0500 Subject: [PATCH] add cors rules --- _docker/nginx/test/conf.d/nginx.conf | 1 - app/Http/Middleware/TrustProxies.php | 9 +++++++-- config/cors.php | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/_docker/nginx/test/conf.d/nginx.conf b/_docker/nginx/test/conf.d/nginx.conf index ea07586..d394af7 100644 --- a/_docker/nginx/test/conf.d/nginx.conf +++ b/_docker/nginx/test/conf.d/nginx.conf @@ -21,7 +21,6 @@ server { root /var/www/public; location / { - add_header Access-Control-Allow-Origin *; # Заголовок для CORS try_files $uri /index.php?$args; # Обработка запросов } diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php index 5915c8f..95a380f 100644 --- a/app/Http/Middleware/TrustProxies.php +++ b/app/Http/Middleware/TrustProxies.php @@ -10,9 +10,14 @@ class TrustProxies extends Middleware /** * The trusted proxies for this application. * - * @var string|array + * @var array|string|null */ - protected $proxies = '*'; + protected $proxies = [ + '127.0.0.1', + '10.0.0.0/8', + '172.16.0.0/12', + '192.168.0.0/16', + ]; /** * The headers that should be used to detect proxies. diff --git a/config/cors.php b/config/cors.php index 2a37e0e..e7277c9 100644 --- a/config/cors.php +++ b/config/cors.php @@ -2,15 +2,15 @@ return [ - 'paths' => ['*'], + 'paths' => ['api/*', 'sanctum/csrf-cookie'], - 'allowed_methods' => ['*'], + 'allowed_methods' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], - 'allowed_origins' => ['*'], + 'allowed_origins' => [env('APP_URL', 'http://localhost')], 'allowed_origins_patterns' => [], - 'allowed_headers' => ['*'], + 'allowed_headers' => ['Content-Type', 'X-Auth-Token', 'Authorization', 'X-Requested-With'], 'exposed_headers' => [],