-
-
Save cookavich/348349fa0ab625a6b40168ca821adf0b to your computer and use it in GitHub Desktop.
Need to do something like this to serve APIs that are going to be consumed by JS clients.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::before(function($request) { | |
if ($request->getMethod() == 'OPTIONS') { | |
$response = Response::make('', 204); | |
$response->header('Access-Control-Allow-Methods', 'GET, POST, PUT, OPTIONS'); | |
$response->header('Access-Control-Allow-Origin', '*'); | |
$response->header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization'); | |
return $response; | |
} | |
}); | |
App::after(function($request, $response) { | |
$response->header('Access-Control-Allow-Methods', 'GET, POST, PUT, OPTIONS'); | |
$response->header('Access-Control-Allow-Origin', '*'); | |
$response->header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment