Skip to content

Latest commit

 

History

History
24 lines (19 loc) · 920 Bytes

File metadata and controls

24 lines (19 loc) · 920 Bytes
sidebar_position 10
sidebar_label CORS Support

CORS support

Note: For general middleware usage patterns, see Middleware.

Enable the Server Handler process the CORS headers and block the access if the origin doesn't match.

<?php
$corsMiddleware = new \ByJG\RestServer\Middleware\CorsMiddleware();
$corsMiddleware
    ->withCorsOrigins([/* list of accepted origin */])  // Required to enable CORS
    ->withAcceptCorsMethods([/* list of methods */])     // Optional. Default all methods. Don't need to pass 'OPTIONS'
    ->withAcceptCorsHeaders([/* list of headers */])     // Optional. Default all headers

Note that the method withCorsOrigins accept a list of hosts regular expressions. e.g.

  • example\.com - Accept only example.com
  • example\.(com|org) - Accept both example.com and example.org
  • example\.com(\.br)? -Accept both example.com and example.com.br