Commit 7d17982e authored by shajiaiming's avatar shajiaiming

cors

parent bc9d6ae7
...@@ -48,6 +48,17 @@ class BaseController extends Controller ...@@ -48,6 +48,17 @@ class BaseController extends Controller
if (\Yii::$app->request->headers->get('FZM-CURRENCY-ID')) { if (\Yii::$app->request->headers->get('FZM-CURRENCY-ID')) {
$this->currency_id = \Yii::$app->request->headers->get('FZM-CURRENCY-ID'); $this->currency_id = \Yii::$app->request->headers->get('FZM-CURRENCY-ID');
} }
$allow_list = array_unique(\Yii::$app->params['allow_options_domain']['allow_options_domain']);
$origin = \Yii::$app->request->headers->get('Origin');
if (!in_array($origin, $allow_list)) {
$origin = implode(',', $allow_list);
}
$this->header('Access-Control-Allow-Origin', $origin);
$this->header('Access-Control-Allow-Methods', 'POST,GET,OPTIONS,PUT,DELETE');
$this->header('Access-Control-Allow-Credentials', 'true');
$this->header('Access-Control-Allow-Headers', 'Authorization,FZM-REQUEST-OS,FZM-USER-IP,FZM-REQUEST-UUID,FZM-PLATFORM-ID,Content-Type,Content-Length');
} }
public function beforeAction($action) public function beforeAction($action)
...@@ -148,4 +159,14 @@ class BaseController extends Controller ...@@ -148,4 +159,14 @@ class BaseController extends Controller
return $models; return $models;
} }
public function header($key, $value)
{
$this->header_list[$key] = $value;
}
public function getHeaders()
{
return $this->header_list;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment