FIX_CORS_ISSUE

This commit is contained in:
VENKATESHWARAN 2026-06-15 16:32:42 +05:30
parent e7b7ca1515
commit 5f0491aa8e
4 changed files with 53 additions and 12 deletions

View File

@ -3,7 +3,7 @@
namespace Config;
use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Debug\ExceptionHandler;
use App\Debug\CorsExceptionHandler;
use CodeIgniter\Debug\ExceptionHandlerInterface;
use Psr\Log\LogLevel;
use Throwable;
@ -99,6 +99,6 @@ class Exceptions extends BaseConfig
*/
public function handler(int $statusCode, Throwable $exception): ExceptionHandlerInterface
{
return new ExceptionHandler($this);
return new CorsExceptionHandler($this);
}
}

View File

@ -7822,20 +7822,18 @@ class ClientController extends AdminController
->join('employees', 'clients.id = employees.client_id', 'left')
->join('employee_polices', 'employees.id = employee_polices.employee_id', 'left')
->where('client_policy.is_active', 1)
// ->where('insurers.is_active', 1)
// ->where('tpa.is_active', 1)
->where('employees.is_active', 1)
->where('employees.relationship', "Self")
->where('employee_polices.is_active', 1)
->whereIn('employees.emp_status', ['active', 'expired'])
->whereIn('employee_polices.status', ['active', 'expired'])
->where('employees.is_active', 1)
->where('client_policy.id', $param)
->where('employee_polices.client_policy_id', $param)
->groupBy('employees.emp_code')
->get()
->getResultArray();
// print_r(db_connect()->getLastQuery()); die;
// print_r(db_connect()->getLastQuery()->getQuery()); die;
$dataForClientAndInsurer = $this->clientPolicyModel
->select("
@ -7938,8 +7936,8 @@ class ClientController extends AdminController
->join('employees', 'clients.id = employees.client_id')
->join('employee_polices', 'employees.id = employee_polices.employee_id AND client_policy.id = employee_polices.client_policy_id')
->where('client_policy.is_active', 1)
->where('insurers.is_active', 1)
->where('tpa.is_active', 1)
// ->where('insurers.is_active', 1)
// ->where('tpa.is_active', 1)
->where('employees.is_active', 1)
->whereIn('employees.emp_status', ['active', 'expired'])
->where('employees.relationship', "Self")
@ -7964,7 +7962,7 @@ class ClientController extends AdminController
$data = $query->get()->getRowArray();
// print_r(db_connect()->getLastQuery()); die;
// print_r(db_connect()->getLastQuery()->getQuery()); die;
$memberData = [];
$dataForClientAndInsurer = [];

View File

@ -0,0 +1,39 @@
<?php
namespace App\Debug;
use App\Filters\Cors;
use CodeIgniter\Debug\ExceptionHandler;
use CodeIgniter\Debug\ExceptionHandlerInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Config\Exceptions;
use Throwable;
/**
* Ensures CORS headers are present on uncaught exception responses.
*
* The global Cors filter's after() method is not invoked when an exception
* bypasses the normal filter pipeline.
*/
class CorsExceptionHandler implements ExceptionHandlerInterface
{
protected ExceptionHandler $handler;
public function __construct(Exceptions $config)
{
$this->handler = new ExceptionHandler($config);
}
public function handle(
Throwable $exception,
RequestInterface $request,
ResponseInterface $response,
int $statusCode,
int $exitCode
): void {
(new Cors())->after($request, $response);
$this->handler->handle($exception, $request, $response, $statusCode, $exitCode);
}
}

View File

@ -355,9 +355,13 @@ class Cors implements FilterInterface
return $response;
}
// For non-OPTIONS requests, don't return a response
// Let the request proceed to the controller
// CORS headers will be added in after() method
// Apply CORS headers on the shared response before other before-filters run.
// When a before-filter returns early (4xx/5xx), CodeIgniter skips after-filters,
// so relying only on after() leaves error responses without CORS headers.
if (! empty($origin) && $this->isOriginAllowed($origin)) {
$this->addCorsHeaders(Services::response(), $request, $origin, false);
}
return null;
}