API cross origin

Hi there

I'm working on a inventory web app here and I'm trying to gather some basic
information about registered hosts to foreman using the API.

Browsers preflight ajax requests to different domains with an OPTIONS
request…

"the specification mandates that browsers "preflight" the request,
soliciting supported methods from the server with an HTTP OPTIONS request
method, and then, upon "approval" from the server, sending the actual
request with the actual HTTP request method."

This isn't working with foreman, the OPTIONS request returns a 404. Here's
the snippet from production.log

Started OPTIONS "/api/v2/hosts" for x.x.x.x at 2014-12-24 08:45:06 +0100

ActionController::RoutingError (No route matches [OPTIONS] "/api/v2/hosts"):

/usr/lib/ruby/gems/1.8/gems/passenger-4.0.18/lib/phusion_passenger/rack/thread_handler_extension.rb:77:in
`process_request'

/usr/lib/ruby/gems/1.8/gems/passenger-4.0.18/lib/phusion_passenger/request_handler/thread_handler.rb:140:in
`accept_and_process_next_request'

/usr/lib/ruby/gems/1.8/gems/passenger-4.0.18/lib/phusion_passenger/request_handler/thread_handler.rb:108:in
`main_loop'

/usr/lib/ruby/gems/1.8/gems/passenger-4.0.18/lib/phusion_passenger/request_handler.rb:441:in
`block (3 levels) in start_threads'

We have added these options to apache but this doesn't help.
I guess it's because everything goes to foreman / passenger anyway…

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods: "GET, POST, PUT, DELETE, 

OPTIONS"

We're running foreman 1.6.2.
Any help would be appreciated.

Regards
Sandro

> Hi there
>
> I'm working on a inventory web app here and I'm trying to gather some
> basic information about registered hosts to foreman using the API.
>
> Browsers preflight ajax requests to different domains with an OPTIONS
> request…
>
> https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
> "the specification mandates that browsers "preflight" the request,
> soliciting supported methods from the server with an HTTP OPTIONS request
> method, and then, upon "approval" from the server, sending the actual
> request with the actual HTTP request method."
>
> This isn't working with foreman, the OPTIONS request returns a 404. Here's
> the snippet from production.log
>
> Started OPTIONS "/api/v2/hosts" for x.x.x.x at 2014-12-24 08:45:06 +0100
>
> ActionController::RoutingError (No route matches [OPTIONS]
> "/api/v2/hosts"):
>
> /usr/lib/ruby/gems/1.8/gems/passenger-4.0.18/lib/phusion_passenger/rack/thread_handler_extension.rb:77:in
> process_request' > > /usr/lib/ruby/gems/1.8/gems/passenger-4.0.18/lib/phusion_passenger/request_handler/thread_handler.rb:140:in >accept_and_process_next_request'
>
> /usr/lib/ruby/gems/1.8/gems/passenger-4.0.18/lib/phusion_passenger/request_handler/thread_handler.rb:108:in
> main_loop' > > /usr/lib/ruby/gems/1.8/gems/passenger-4.0.18/lib/phusion_passenger/request_handler.rb:441:in >block (3 levels) in start_threads'
>
> We have added these options to apache but this doesn't help.
> I guess it's because everything goes to foreman / passenger anyway…
>
> Header set Access-Control-Allow-Origin "*"
> Header set Access-Control-Allow-Methods: "GET, POST, PUT, DELETE,
> OPTIONS"
>
>
> We're running foreman 1.6.2.
> Any help would be appreciated.
>

You probably have two options:

  1. proxy the whole request, so the browser and hits a proxy that serves
    both apps routes.
  2. use the rack-cors gem.

Ohad

··· On Wed, Dec 24, 2014 at 10:34 AM, Sandro Roth wrote:

Regards
Sandro


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

Yeah I will probably have to create a proxy that does the api calls to
foreman.

Thanks
Sandro

··· On Wednesday, December 24, 2014 9:36:38 AM UTC+1, ohad wrote: > > > > On Wed, Dec 24, 2014 at 10:34 AM, Sandro Roth > wrote: > >> Hi there >> >> I'm working on a inventory web app here and I'm trying to gather some >> basic information about registered hosts to foreman using the API. >> >> Browsers preflight ajax requests to different domains with an OPTIONS >> request.. >> >> https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS >> "the specification mandates that browsers "preflight" the request, >> soliciting supported methods from the server with an HTTP OPTIONS request >> method, and then, upon "approval" from the server, sending the actual >> request with the actual HTTP request method." >> >> This isn't working with foreman, the OPTIONS request returns a 404. >> Here's the snippet from production.log >> >> Started OPTIONS "/api/v2/hosts" for x.x.x.x at 2014-12-24 08:45:06 +0100 >> >> ActionController::RoutingError (No route matches [OPTIONS] >> "/api/v2/hosts"): >> >> /usr/lib/ruby/gems/1.8/gems/passenger-4.0.18/lib/phusion_passenger/rack/thread_handler_extension.rb:77:in >> `process_request' >> >> /usr/lib/ruby/gems/1.8/gems/passenger-4.0.18/lib/phusion_passenger/request_handler/thread_handler.rb:140:in >> `accept_and_process_next_request' >> >> /usr/lib/ruby/gems/1.8/gems/passenger-4.0.18/lib/phusion_passenger/request_handler/thread_handler.rb:108:in >> `main_loop' >> >> /usr/lib/ruby/gems/1.8/gems/passenger-4.0.18/lib/phusion_passenger/request_handler.rb:441:in >> `block (3 levels) in start_threads' >> >> We have added these options to apache but this doesn't help. >> I guess it's because everything goes to foreman / passenger anyway.. >> >> Header set Access-Control-Allow-Origin "*" >> Header set Access-Control-Allow-Methods: "GET, POST, PUT, DELETE, >> OPTIONS" >> >> >> We're running foreman 1.6.2. >> Any help would be appreciated. >> > > You probably have two options: > > 1. proxy the whole request, so the browser and hits a proxy that serves > both apps routes. > 2. use the rack-cors gem. > > Ohad > >> >> >> Regards >> Sandro >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Foreman users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to foreman-user...@googlegroups.com . >> To post to this group, send email to forema...@googlegroups.com >> . >> Visit this group at http://groups.google.com/group/foreman-users. >> For more options, visit https://groups.google.com/d/optout. >> > >