Last active
September 16, 2022 00:16
-
-
Save adamwathan/7921405 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 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