Skip to content
Snippets Groups Projects
Commit 9d9ed2d1 authored by Brett Bieber's avatar Brett Bieber
Browse files

Send CORS headers so content can be included

parent b7f219d4
No related branches found
No related tags found
No related merge requests found
...@@ -92,4 +92,32 @@ class OutputController extends \Savvy ...@@ -92,4 +92,32 @@ class OutputController extends \Savvy
} }
} }
/**
*
* @param timestamp $expires timestamp
*
* @return void
*/
function sendCORSHeaders($expires = null)
{
// Specify domains from which requests are allowed
header('Access-Control-Allow-Origin: *');
// Specify which request methods are allowed
header('Access-Control-Allow-Methods: GET, OPTIONS');
// Additional headers which may be sent along with the CORS request
// The X-Requested-With header allows jQuery requests to go through
header('Access-Control-Allow-Headers: X-Requested-With');
// Set the ages for the access-control header to 20 days to improve speed/caching.
header('Access-Control-Max-Age: 1728000');
if (isset($expires)) {
// Set expires header for 24 hours to improve speed caching.
header('Expires: '.date('r', $expires));
}
}
} }
...@@ -30,5 +30,5 @@ $catalog = new Controller($router->route($_SERVER['REQUEST_URI'], $_GET)); ...@@ -30,5 +30,5 @@ $catalog = new Controller($router->route($_SERVER['REQUEST_URI'], $_GET));
$savvy = new OutputController($catalog->options); $savvy = new OutputController($catalog->options);
$savvy->addGlobal('controller', $catalog); $savvy->addGlobal('controller', $catalog);
$savvy->addGlobal('course_search_driver', new CourseSearch\DBSearcher()); $savvy->addGlobal('course_search_driver', new CourseSearch\DBSearcher());
$savvy->sendCORSHeaders(strtotime('tomorrow'));
echo $savvy->render($catalog); echo $savvy->render($catalog);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment