This commit is contained in:
andrey 2021-06-14 17:26:05 +03:00
parent b9f919204c
commit 65e50ad36a
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<?php
namespace common\behaviors;
use yii\filters\Cors;
class GsCors extends Cors
{
public function prepareHeaders($requestHeaders){
$responseHeaders = parent::prepareHeaders($requestHeaders);
if (isset($this->cors['Access-Control-Allow-Headers'])) {
$responseHeaders['Access-Control-Allow-Headers'] = implode(', ', $this->cors['Access-Control-Allow-Headers']);
}
return $responseHeaders;
}
}

View File

@ -2,6 +2,7 @@
namespace frontend\modules\api\controllers;
use common\behaviors\GsCors;
use common\models\Options;
use yii\filters\AccessControl;
@ -16,6 +17,19 @@ class SkillsController extends \yii\rest\Controller
'application/json' => \yii\web\Response::FORMAT_JSON,
],
],
'corsFilter' => [
'class' => GsCors::class,
'cors' => [
'Origin' => ['*'],
'Access-Control-Allow-Credentials' => true,
'Access-Control-Allow-Headers' => [
'Content-Type',
'Access-Control-Allow-Headers',
'Authorization',
'X-Requested-With'
],
]
]
];
}