AccessControlMiddleware.php 675 B

12345678910111213141516171819202122
  1. <?php
  2. namespace app\admin\middleware;
  3. use Webman\MiddlewareInterface;
  4. use Webman\Http\Response;
  5. use Webman\Http\Request;
  6. class AccessControlMiddleware implements MiddlewareInterface
  7. {
  8. public function process(Request $request, callable $handler) : Response
  9. {
  10. $response = $request->method() == 'OPTIONS' ? response('') : $handler($request);
  11. $response->withHeaders([
  12. 'Access-Control-Allow-Credentials' => 'true',
  13. 'Access-Control-Allow-Origin' => $request->header('Origin', '*'),
  14. 'Access-Control-Allow-Methods' => '*',
  15. 'Access-Control-Allow-Headers' => '*',
  16. ]);
  17. return $response;
  18. }
  19. }