Welcome Guest, Not a member yet? Register   Sign In
CORS in method delete
#4

Use this middlewear (filter)

<?php namespace Modules\Common\Filters;

use CodeIgniter\config\Services;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;


class CorsFilter implements FilterInterface
{
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{


}

public function before(RequestInterface $request, $arguments = null)
{



if (array_key_exists('HTTP_ORIGIN', $_SERVER)) {
$origin = $_SERVER['HTTP_ORIGIN'];
} else if (array_key_exists('HTTP_REFERER', $_SERVER)) {
$origin = $_SERVER['HTTP_REFERER'];
} else {
$origin = $_SERVER['REMOTE_ADDR'];
}
$allowed_domains = array(
'http://localhost:4200',
'https://exmple.com',
'https://www.exmple.com',
);


if (in_array($origin, $allowed_domains)) {
header('Access-Control-Allow-Origin: ' . $origin);
}

header("Access-Control-Allow-Headers: Origin, X-API-KEY, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Allow-Headers, Authorization, observe, enctype, Content-Length, X-Csrf-Token");
header("Access-Control-Allow-Methods: GET, PUT, POST, DELETE, PATCH, OPTIONS");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 3600");
header('content-type: application/json; charset=utf-8');
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "OPTIONS") {
header("HTTP/1.1 200 OK CORS");
die();
}

}


}
Enlightenment  Is  Freedom
Reply


Messages In This Thread
CORS in method delete - by rafinhaa - 10-08-2021, 01:43 PM
RE: CORS in method delete - by kenjis - 10-08-2021, 11:26 PM
RE: CORS in method delete - by InsiteFX - 10-09-2021, 12:37 AM
RE: CORS in method delete - by paliz - 10-09-2021, 12:57 AM
RE: CORS in method delete - by rafinhaa - 10-11-2021, 08:28 AM
RE: CORS in method delete - by paliz - 10-11-2021, 12:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB