С postman и с мобилы все ходит норм, авторизация через bearer token. Работает отлично.
Делаю SPA на vue.js. Отправляю тот же post(библиотека axios) что с мобилы и postman
Получаю:
"Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8085' is therefore not allowed access. The response had HTTP status code 404."
Нашел решение что бы убрать это дерьмо cors и сделал так:
Код: Выделить всё
class RetailController extends Controller
{
public $modelClass = 'api\models\Userupdate';
public $enableCsrfValidation = false;
public static function allowedDomains() {
return [
'*',
'http://test1.example.com',
'http://test2.example.com',
];
}
public function behaviors()
{
$behaviors = parent::behaviors();
// add CORS filter
$behaviors['corsFilter'] = [
'class' => \yii\filters\Cors::className(),
'cors' => [
// restrict access to domains:
'Origin' => static::allowedDomains(),
'Access-Control-Request-Method' => ['POST'],
'Access-Control-Allow-Credentials' => true,
'Access-Control-Max-Age' => 3600, // Cache (seconds)
],
];
$behaviors['authenticator']['authMethods'] = [
//HttpBasicAuth::className(),
HttpBearerAuth::className(),
];
$behaviors['access'] = [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
],
],
];
return $behaviors;
}
Что можно сделать что бы я могу отправить post с другого домена ?!