My front-end application is running on a grunt live server on port 9100, while my PHP server is on the port 80. The host is the same, just the port differ.
When I send a POST request to http://dev.site.dev/api/gist with some JSON data, I got an error 404 on the preflight OPTIONS request.
I already added the CORS headers in apache configuration:
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "X-Requested-With, accept, content-type"
Header set Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
``` and restart the server but still got the issue.
Should I add an index_option() method in my gist controller ? Or the problem is somewhere else ?
As I described in my answer on the
CodeIgniterbug tracker for this "issue" #313, there is several solutions.Application wide
I found a solution from HTTP OPTIONS error in Phil Sturgeon's Codeigniter Restserver and Backbone.js, which is to remove
otpionsfrom the list of value in$allowed_http_methods:Resource's focused
Another solution is to simply implement the
index_options().It didn't work for me the first time due to a typo (it's
OPTIONSis plural ). And with this solution no more need to temper withapplications/libraries/REST_Controller.php:Now the preflight
OPTIONrequest is always true so thePOSTrequest is sent and everything works :)