Hey guys.
I have the problem with CORS, I’m try to send a Id in the URL and for that I define a pattern in my config
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'showScriptName' => false,
'rules' => [
[
'class' => UrlRule::class, 'controller' => [
'user',
'controller1',
'controller2',
'controller3'
],
'pluralize' => false,
],
[
'pattern' => '/controller1/specialword/<my_id:\d+>',
'route' => 'controller1/index',
'normalizer' => false
]
in the principal Controller I have the following:
class ActiveController extends \yii\rest\ActiveController
{
public function behaviors()
{
$behaviors = parent::behaviors();
// remove auth filter before cors if you are using it
unset($behaviors['authenticator']);
$behaviors['corsFilter'] = [
'class' => \yii\filters\Cors::class,
'cors' => [
'Origin' => [Yii::$app->request->getOrigin()],
'Access-Control-Allow-Credentials' => true,
'Access-Control-Request-Method' => ['GET', 'POST', 'PUT'],
'Access-Control-Request-Headers' => ['*'],
],
];
// re-add authentication filter if you are using it.
$behaviors['authenticator'] = [
'class' => HttpBearerAuth::class,
];
$behaviors['authenticator']['except'] = ['login'];
return $behaviors;
}
In POSTMAN working fine but with my front I have the following error:
Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.