api cors
This commit is contained in:
parent
fd384ec957
commit
57cb9df4bf
30
frontend/modules/api/controllers/ApiController.php
Normal file
30
frontend/modules/api/controllers/ApiController.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace frontend\modules\api\controllers;
|
||||||
|
|
||||||
|
use common\behaviors\GsCors;
|
||||||
|
use yii\rest\Controller;
|
||||||
|
|
||||||
|
class ApiController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
public function behaviors()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'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'
|
||||||
|
],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -12,17 +12,20 @@ use kavalar\TelegramBotService;
|
|||||||
use yii\filters\auth\CompositeAuth;
|
use yii\filters\auth\CompositeAuth;
|
||||||
use yii\filters\auth\HttpBearerAuth;
|
use yii\filters\auth\HttpBearerAuth;
|
||||||
use yii\filters\auth\QueryParamAuth;
|
use yii\filters\auth\QueryParamAuth;
|
||||||
|
use yii\filters\ContentNegotiator;
|
||||||
|
use yii\web\Response;
|
||||||
|
|
||||||
class ProfileController extends \yii\rest\Controller
|
class ProfileController extends ApiController
|
||||||
{
|
{
|
||||||
|
|
||||||
public function behaviors()
|
public function behaviors()
|
||||||
{
|
{
|
||||||
return [
|
$parent = parent::behaviors();
|
||||||
|
$b = [
|
||||||
[
|
[
|
||||||
'class' => \yii\filters\ContentNegotiator::className(),
|
'class' => ContentNegotiator::className(),
|
||||||
'formats' => [
|
'formats' => [
|
||||||
'application/json' => \yii\web\Response::FORMAT_JSON,
|
'application/json' => Response::FORMAT_JSON,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'authenticator' => [
|
'authenticator' => [
|
||||||
@ -31,20 +34,9 @@ class ProfileController extends \yii\rest\Controller
|
|||||||
HttpBearerAuth::class,
|
HttpBearerAuth::class,
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
// 'corsFilter' => [
|
|
||||||
// 'class' => GsCors::class,
|
|
||||||
// 'cors' => [
|
|
||||||
// 'Origin' => ['https://itguild.info'],
|
|
||||||
// //'Access-Control-Allow-Credentials' => true,
|
|
||||||
// 'Access-Control-Allow-Headers' => [
|
|
||||||
// 'Content-Type',
|
|
||||||
// 'Access-Control-Allow-Headers',
|
|
||||||
// 'Authorization',
|
|
||||||
// 'X-Requested-With'
|
|
||||||
// ],
|
|
||||||
// ]
|
|
||||||
// ]
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
return array_merge($parent, $b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionIndex($id = null)
|
public function actionIndex($id = null)
|
||||||
|
@ -11,12 +11,11 @@ use Yii;
|
|||||||
use yii\filters\auth\CompositeAuth;
|
use yii\filters\auth\CompositeAuth;
|
||||||
use yii\filters\auth\HttpBearerAuth;
|
use yii\filters\auth\HttpBearerAuth;
|
||||||
use yii\filters\ContentNegotiator;
|
use yii\filters\ContentNegotiator;
|
||||||
use yii\rest\Controller;
|
|
||||||
use yii\web\BadRequestHttpException;
|
use yii\web\BadRequestHttpException;
|
||||||
use yii\web\NotFoundHttpException;
|
use yii\web\NotFoundHttpException;
|
||||||
use yii\web\Response;
|
use yii\web\Response;
|
||||||
|
|
||||||
class ReportsController extends Controller
|
class ReportsController extends ApiController
|
||||||
{
|
{
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
@ -25,26 +24,14 @@ class ReportsController extends Controller
|
|||||||
|
|
||||||
public function behaviors()
|
public function behaviors()
|
||||||
{
|
{
|
||||||
return [
|
$parent = parent::behaviors();
|
||||||
|
$b = [
|
||||||
[
|
[
|
||||||
'class' => ContentNegotiator::className(),
|
'class' => ContentNegotiator::className(),
|
||||||
'formats' => [
|
'formats' => [
|
||||||
'application/json' => Response::FORMAT_JSON,
|
'application/json' => 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'
|
|
||||||
// ],
|
|
||||||
// ]
|
|
||||||
// ],
|
|
||||||
'authenticator' => [
|
'authenticator' => [
|
||||||
'class' => CompositeAuth::class,
|
'class' => CompositeAuth::class,
|
||||||
'authMethods' => [
|
'authMethods' => [
|
||||||
@ -52,6 +39,8 @@ class ReportsController extends Controller
|
|||||||
],
|
],
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
return array_merge($parent, $b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionIndex(): array
|
public function actionIndex(): array
|
||||||
|
@ -8,16 +8,19 @@ use yii\filters\AccessControl;
|
|||||||
use yii\filters\auth\CompositeAuth;
|
use yii\filters\auth\CompositeAuth;
|
||||||
use yii\filters\auth\HttpBearerAuth;
|
use yii\filters\auth\HttpBearerAuth;
|
||||||
use yii\filters\auth\QueryParamAuth;
|
use yii\filters\auth\QueryParamAuth;
|
||||||
|
use yii\filters\ContentNegotiator;
|
||||||
|
use yii\web\Response;
|
||||||
|
|
||||||
class SkillsController extends \yii\rest\Controller
|
class SkillsController extends ApiController
|
||||||
{
|
{
|
||||||
public function behaviors()
|
public function behaviors()
|
||||||
{
|
{
|
||||||
return [
|
$parent = parent::behaviors();
|
||||||
|
$b = [
|
||||||
[
|
[
|
||||||
'class' => \yii\filters\ContentNegotiator::className(),
|
'class' => ContentNegotiator::className(),
|
||||||
'formats' => [
|
'formats' => [
|
||||||
'application/json' => \yii\web\Response::FORMAT_JSON,
|
'application/json' => Response::FORMAT_JSON,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'authenticator' => [
|
'authenticator' => [
|
||||||
@ -26,20 +29,9 @@ class SkillsController extends \yii\rest\Controller
|
|||||||
HttpBearerAuth::class,
|
HttpBearerAuth::class,
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
// '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'
|
|
||||||
// ],
|
|
||||||
// ]
|
|
||||||
// ]
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
return array_merge($parent, $b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionIndex()
|
public function actionIndex()
|
||||||
|
@ -36,19 +36,19 @@ class UserController extends ActiveController
|
|||||||
// HttpBearerAuth::class,
|
// HttpBearerAuth::class,
|
||||||
// ],
|
// ],
|
||||||
// ],
|
// ],
|
||||||
// 'corsFilter' => [
|
'corsFilter' => [
|
||||||
// 'class' => GsCors::class,
|
'class' => GsCors::class,
|
||||||
// 'cors' => [
|
'cors' => [
|
||||||
// 'Origin' => ['*'],
|
'Origin' => ['*'],
|
||||||
// //'Access-Control-Allow-Credentials' => true,
|
//'Access-Control-Allow-Credentials' => true,
|
||||||
// 'Access-Control-Allow-Headers' => [
|
'Access-Control-Allow-Headers' => [
|
||||||
// 'Content-Type',
|
'Content-Type',
|
||||||
// 'Access-Control-Allow-Headers',
|
'Access-Control-Allow-Headers',
|
||||||
// 'Authorization',
|
'Authorization',
|
||||||
// 'X-Requested-With'
|
'X-Requested-With'
|
||||||
// ],
|
],
|
||||||
// ]
|
]
|
||||||
// ]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user