Skip to content

Instantly share code, notes, and snippets.

@adrianpietka
Last active October 24, 2017 21:35
Show Gist options
  • Select an option

  • Save adrianpietka/253c494c41b4a49bc5a9d8d7ff7aaa00 to your computer and use it in GitHub Desktop.

Select an option

Save adrianpietka/253c494c41b4a49bc5a9d8d7ff7aaa00 to your computer and use it in GitHub Desktop.
Silex + CORS

Allow:

  • access from every host (1)
  • use HTTP headers Authorization-Key and Origin (2)
  • use HTTP methods GET, POST, PUT, DELETE, OPTIONS (3)
<?php

$app->after(function (Request $request, Response $response) {
    $response->headers->set('Access-Control-Allow-Origin', '*'); // (1)
    $response->headers->set('Access-Control-Allow-Headers', 'Authorization-Key, Origin'); // (2)
    $response->headers->set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); // (3)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment