request = $request; } public function afterController($controller, $methodName, Response $response) { if($response instanceof JSONResponse){ $origin = $this->request->server['HTTP_ORIGIN']; if($origin) { $response->addHeader('Access-Control-Allow-Origin', $origin); } } return parent::afterController($controller, $methodName, $response); } }