cors
This commit is contained in:
parent
b9f919204c
commit
65e50ad36a
22
common/behaviors/GsCors.php
Normal file
22
common/behaviors/GsCors.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
@ -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'
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user