diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index ee7c3e1..78d0f5f 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -133,6 +133,14 @@ class Application extends \Illuminate\Container\Container implements \Illuminate */ protected $builtViewGlobals = null; + + /** + * Allow Cross Origin Requests + * @boolean allow + */ + + protected $allow = false; + /** * Constructs the application and ensures it's correctly setup. */ @@ -299,6 +307,10 @@ public function loadPlugin($config) $this->addPluginComposers( array_get($config, 'viewComposers', []) ); + + $this->allowCORSDomains( + array_get($config, 'CORS', false ,[]) + ); } /** @@ -1274,4 +1286,26 @@ public function getCachedServicesPath() return $this->basePath() . '/vendor/services.json'; } + + /** + * Allow the Http request from different sources(CORS) + * + */ + + public function allowCORSDomains($allow, $domains =[]) + { + if($allow == true){ + + $origin = $_SERVER['HTTP_REFERER']; + if(in_array($origin, $domains)){ + + add_action('init', 'add_origins'); + function add_origins(){ + header("Access-Control-Allow-Origin: " .$_SERVER['HTTP_ORIGIN']); + } + } + } + } + + }