Skip to content

Instantly share code, notes, and snippets.

@mcrumm
Created January 10, 2013 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcrumm/4498655 to your computer and use it in GitHub Desktop.
Save mcrumm/4498655 to your computer and use it in GitHub Desktop.
I feel like there has to be a better way to deal with these requests... New project, AngularJS client-side, Slim (or Silex, I'm playing with both) server-side. Every request from AngularJS attempts an OPTIONS request first, which isn't a valid route. I'd MUCH rather proxy the requests to a single method via application middleware, but the sheer …
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "X-Requested-With"
Header set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Stupidly handle CORS requests here, since wildcard routes are a no-go.
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^ cors.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: X-Requested-With');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment