Rails, proxy request to another url without starting an application - ruby-on-rails

I have a Rails app running on e.g. example.com.
Any request is processed by Rails router.
There is public API on e.g. example.com/rest/2.0/session.
API is done on PHP and is unrelated to main app.
Is it possible to proxy requests to API bypassing Rails application?
Sorry in advance, no clues found in internet.

Configuring directories in apache.
You can have your rails application in /var/www/ruby/myapp and PHP api code in /var/www/php/.

Related

Web server and application server Ruby on rails

Best practice for Scalable project on ruby on rails. Problem: I don't understand the difference between web and app server in ror projects.
I understood that the differences between application and web servers are webserver handles requests and application has business logic. However I don't quite understand how I can implement it in my ruby on rails application.
So, I have, for example, two instances and ruby on rails application.
On the first server I want to set up a web server, and on the second one I want to install application server.
But, for example, I use passengers as my webserver that makes easier to deploy my ror application. So, will I have any benefits implementing such logic? Can I use passenger as an cache server or something like this? Is it possible to put passenger on another server and send request to ror application? Or I totally wrong and don't understand the conception?
Note: I just found amazon web application hosting architecture and now I'm trying to figure out how I can it implement and how it could work.
Use heroku with puma. That's the easiest to setup.
http://www.justinweiss.com/articles/a-web-server-vs-an-app-server/
https://www.nateberkopec.com/2015/07/29/scaling-ruby-apps-to-1000-rpm.html
https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server

How to make requests to a local Rails app from a local AngularJS app running on a different port?

I'm developing a web application with an AngularJS frontend and a Rails backend.
My goal is to keep the two entirely separate, since the Rails app will ultimately be relegated to a simple REST server, and the AngularJS frontend will be just one of a few different clients that use the backend. For that reason, I don't want to integrate the frontend into the Rails asset pipeline, or similar.
The Rails app is running locally on port 3000. The frontend uses Gulp to compile static assets, and BrowserSync, which contains a development server that I'm running on port 3001.
For development purposes, how can I get the AngularJS app to talk to the Rails server, avoiding this browser error (which I'd expected) when making HTTP request via Angular's $http service?
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:3001' is therefore not allowed access.
Do I just need to set up CORS in the Rails app? Is there another way - maybe some sort of local hosts file trick (I'm on a Mac, FWIW) or similar? I ask because my coworker is responsible for the Rails app (I have limited experience with Rails) but is out of town for a while; my knowledge is mostly limited to the AngularJS stack that I've set up.
I've searched and read up for about an hour, but haven't yet been able to find anything that I can grok that is applicable to my situation. I might not be aware of the best search terms.
Thanks for any help!
Ah, wonderful. Here are a few solutions:
set up CORS, which shouldn't be too hard. All you have to do is add the headers to pages serving your static content (not the rails REST endpoints), The problem with this is you shouldn't really be doing it unless you have a good reason (so see 3). How are you serving the static content? There should be plugins to do the headers for you if it's a popular tool
serve the angularJS pages from the rails backend for now (using some kind of static route)
if you're thinking about production and want to sort this out for good, use nginx to proxy the two services into one single domain, http://nginx.org/en/docs/beginners_guide.html

Integrating Guacamole Java Servlet with Rails project

I'm trying to add Guacamole (An html5 vnc client) to an existing rails project but I'm running into some trouble because the Guacamole server is implemented in Java. Based on the overview here http://guac-dev.org/doc/gug/writing-you-own-guacamole-app.html, I need to create 1. a GuacamoleHTTPTunnelServlet (a tunnel between the JavaScript client and the Guacd service) and 2. the javascript client itself. See attached picture for reference. Creating the javascript client seems easy because all the javascript is already given and I would just have to add it to a rails view. The hard part, if possible at all, is integrating the GuacamoleHTTPTunnelServlet java servlet with rails.
Is there any way to have rails serve up the javascript but have the javascript communicate with a different server on the same machine? I'm guessing no because of the same origin policy.
Is there any way to forward the javascript calls from rails server -> java servlet without losing performance? I'm not completely clear on how the javascript client communicates with the server but I think it's passing java objects.
I've never tried anything like this before so please excuse me for any stupidity.
I played around with guacamole and I think your best option is to rewrite guacamole backend (that comunicates with guacd daemon) in rails. Anyway I will try to answer to your questions:
You can proxy ajax requests with rack, ex:
How do I proxy AJAX requests with Rack Middleware?
Another way is to use a reverse proxy (nginx?), ex:
http://yourdomain.com/your/rails/view/url
http://yourdomain.com/guacamole
In this manner the client (browser) will think that your applications are under the same host, avoiding the javascript same origin policy. An iframe will be a great solution.
Javascript communicates with tunnel servlet that proxies requests to guacd daemon (no java objects, just a custom protocol). To speed up performances you can use a reverse proxy (answer 1, ex: nginx) instead of ruby/rack solution.
I hope this can help :)

Configuring multiple applications in RoR

I would like to have multiple RoR applications that can communicate with each other (databases, method calls, ...).
Example of what I would like:
a main application running on a URL http:// www.< application_name >.com
a sub-application 1 running on a URL http:// www.< application1_name >.< application_name >.com
a sub-application 2 running on a URL http:// www.< application2_name >.< application_name >.com
each with own databases.
How can I configure my applications? Where can I find a tutorial for my needs?
No Problem. In your case you will have 3 distinct Rails applications. You will setup your Webserver to send requests based on host accessed to one of the three applications. This is standard web server configuration. You'll need to read Apache or Nginx configuration on how to route request to the right rails application.
EDIT:
http://articles.slicehost.com/2009/3/11/ubuntu-intrepid-nginx-rails-and-mongrels
Not sure what you are going to use as your Web Server (Apache or Nginx or something else) or what you are going use as your application container (mongrel/passenger/thin etc) but this article above should help.
You might take a look at the eco_apps gem - https://github.com/idapted/eco_apps. I heard the developers give a talk about it at Rails Conf '10. Fascinating stuff, though I haven't had a chance to use it yet.

web services between rails and j2se

I developed a web site using rails 2.3.8, and a IM server using openfire(java). I want to share some data between them, or exactly rails as provider, openfire as consumer. A possible way is using web service. But it seems that rails 2.x has deprecated the default SOAP support, I installed the gem activewebservice, but there is lack of documents to show how to using it. I googled an example in IBM's site, but there seems something wrong to follow this guide in rails 2.3.8. Can anyone give me an example?
I know there is another way to provide the web service is using rails' default RESTful-type web service, but how to configure the java side to support this?
Rails has support for RESTful web-services OOTB, so if you have developed your rails application using scaffold generator then your application is already providing a RESTful API. Now as your IM server is the consumer, all you have to do is to make your IM server call the RESTful API provided by the rails application.
Calling RESTful API means sending HTTP (GET/POST/PUT/DELETE) requests to the REST server(Rails App). So all you need to do, is plugin some java code to the openfire server which will send the HTTP requests adhering to the REST conventions and send/receive data in a suitable serialization format(XML/JSON/etc). There is a plugin mechanism in openfire which which probably may help you achieve this.
As far as RESTful calls are concerned, this can be achieved in any of the below methods:
Use a REST Client library provided by JAX-RS implementations like Jersey, Apache wink, etc.
Use any HTTP client library to send/receive HTTP requests/response and a XML/JSON/etc library to serialize/de-serialize the data.

Resources