diff --git a/src/UNL/Catalog/OutputController.php b/src/UNL/Catalog/OutputController.php index fe18a6f198e7ff1897a9e9ca53b4dd9969bf97cf..4bc5d24d6a4bca687dd0613b555ca5c3b056826b 100644 --- a/src/UNL/Catalog/OutputController.php +++ b/src/UNL/Catalog/OutputController.php @@ -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)); + } + } + } diff --git a/www/index.php b/www/index.php index bb71d84c16737dba529de6f56ae3c52f15692cf3..976a856905cd5f63cbb4585a57560b7a6558a342 100644 --- a/www/index.php +++ b/www/index.php @@ -30,5 +30,5 @@ $catalog = new Controller($router->route($_SERVER['REQUEST_URI'], $_GET)); $savvy = new OutputController($catalog->options); $savvy->addGlobal('controller', $catalog); $savvy->addGlobal('course_search_driver', new CourseSearch\DBSearcher()); - +$savvy->sendCORSHeaders(strtotime('tomorrow')); echo $savvy->render($catalog); \ No newline at end of file