Topics

Tribe Support

Tribe Support's Topics

Nick Swinford

Nick Swinford

August 11 2016

OPTIONS requests fail

I've been running into a lot of CORS issues lately and even if I set the necessary headers for everything to work, I run into a problem with preflight requests.

A little background here to explain the problem, #CORS or #CrossOriginResourceSharing kicks in whenever you're making a request to a domain that different than you're current on. In my case, I have my fronted at http://localhost:4200 and the API at http://localhost. Before requests are done, the browser does a preflight request, an OPTIONS request, to see what operations are allowed from this location.

The problem here is pretty simple, Anahita returns an error stating that _actionOptions doesn't exist which it doesn't. I did some searching and found KControllerBehaviorDiscoverable which has a _actionOptions function, but after adding the behavior to my controller, it still doesn't work. Not sure why.  

Nick Swinford
Nick Swinford
August 11 2016 Permalink
I copied _actionOptions into my controller and it still doesn't work. I think discoverable needs to be higher up in the chain. Here's my stack trace.

Exception KControllerException with message "Can't execute 'options', method: '_actionOptions' does not exist"

/var/www/html/sgn/vendor/anahita/anahita/vendor/nooku/libraries/koowa/controller/abstract.php:144
/var/www/html/sgn/vendor/anahita/anahita/src/libraries/default/base/dispatcher/component.php:93
/var/www/html/sgn/vendor/anahita/anahita/vendor/nooku/libraries/koowa/controller/abstract.php:147
/var/www/html/sgn/vendor/anahita/anahita/vendor/nooku/libraries/koowa/controller/abstract.php:306
/var/www/html/sgn/vendor/anahita/anahita/src/libraries/default/base/controller/abstract.php:158
/var/www/html/sgn/vendor/anahita/anahita/src/libraries/default/base/dispatcher/application.php:150
/var/www/html/sgn/vendor/anahita/anahita/src/libraries/default/base/dispatcher/application.php:150
/var/www/html/sgn/vendor/anahita/anahita/src/site/components/com_application/dispatcher.php:89
/var/www/html/sgn/vendor/anahita/anahita/vendor/nooku/libraries/koowa/controller/abstract.php:147
/var/www/html/sgn/vendor/anahita/anahita/vendor/nooku/libraries/koowa/controller/abstract.php:306
/var/www/html/sgn/vendor/anahita/anahita/src/libraries/default/base/controller/abstract.php:158
/var/www/html/sgn/vendor/anahita/anahita/src/site/components/com_application/dispatcher.php:132
/var/www/html/sgn/vendor/anahita/anahita/src/site/components/com_application/dispatcher.php:132
/var/www/html/sgn/vendor/anahita/anahita/vendor/nooku/libraries/koowa/controller/abstract.php:147
/var/www/html/sgn/vendor/anahita/anahita/vendor/nooku/libraries/koowa/controller/abstract.php:306
/var/www/html/sgn/vendor/anahita/anahita/src/libraries/default/base/controller/abstract.php:158
/var/www/html/sgn/vendor/anahita/anahita/src/site/components/com_application/dispatcher.php:76
/var/www/html/sgn/vendor/anahita/anahita/src/site/components/com_application/dispatcher.php:76
/var/www/html/sgn/vendor/anahita/anahita/vendor/nooku/libraries/koowa/controller/abstract.php:147
/var/www/html/sgn/vendor/anahita/anahita/vendor/nooku/libraries/koowa/controller/abstract.php:306
/var/www/html/sgn/vendor/anahita/anahita/src/libraries/default/base/controller/abstract.php:158
/var/www/html/sgn/vendor/anahita/anahita/src/site/includes/bootstrap.php:22
/var/www/html/sgn/vendor/anahita/anahita/src/site/includes/bootstrap.php:22
/var/www/html/sgn/www/index.php:24
Rastin Mehr
Rastin Mehr
August 12 2016 Permalink
What type of request are you making? A wild guess is that the behaviour doesn't get included for the type of request you are making. This could be an issue in the version of Nooku Anahita is using and you just have to debug it find the answer. I don't know what's going on unless I play with the code myself.
Nick Swinford
Nick Swinford
August 12 2016 Permalink
It's a PUT request, but it never gets to that point because the the pre-flight OPTION request fails.
Rastin Mehr
Rastin Mehr
August 12 2016 Permalink
How doesn't it respond to POST requests?
Does the PUT request respond when you make a request from the same domain?

I am fully focused on the NoJoomla release now, but feel free to do a PR if you could find a fix or at least find out what's causing the issue.
Nick Swinford
Nick Swinford
August 13 2016 Permalink
I think I get the same error whenever it's a Cross Origin request.

I was able to bypass this issue by reworking some parts of my dev tools and environment so I'm not too concerned about fixing it right now, but it is an issue I've run into a few times, just wanted to get a bug report up.
Rastin Mehr
Rastin Mehr
August 13 2016 Permalink
This probably has little todo with the behaviour and more todo with how the host and server are identified.

Powered by Anahita