Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Herbert/Framework/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -299,6 +307,10 @@ public function loadPlugin($config)
$this->addPluginComposers(
array_get($config, 'viewComposers', [])
);

$this->allowCORSDomains(
array_get($config, 'CORS', false ,[])
);
}

/**
Expand Down Expand Up @@ -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']);
}
}
}
}


}