Created
January 10, 2013 01:36
-
-
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 …
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
<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> |
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 | |
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