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 :)
Related
I want to create a feature on my web portal where a user can click a link to open a telnet session in the browser itself. I researched the Net::Telnet library for Ruby. It has information on how to set up the connection.
But what about the web UI?
How to leverage the Net::Telnet library on the rails web app.
I have Rails 4.2.0 with Apache Passenger running on a CentOS 6.6 machine.
Because telnet is a streaming/serial type protocol and users will expect that type of experience, you might want to look into websockets or streaming http. The only other option would be to do polling to keep your view updated which seems like a very bad fit for a telnet client. Definitely an interesting problem. It appears that Net::Telnet behaves like a tcp socket connection so if you can wire that up to an http stream, which seems possible, you should be able to push it to a browser UI. Sounds like a cool project. Let me know how it takes shape.
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
I am calling a number of apis of a web service hosted on a number of servers. Requests get routed to these servers at random through a load balancer.
All these servers reside on my local network and I want one particular api call to go to one particular server.
Since I don't want other requests to get affected, I am unwilling to put a host entry on the server hosting my app.
Can this be achieved through code?
I am coding in ruby and using net-http gem to make api calls.
Any implementation using curb gem is also welcome.
Thanks
-Azitabh
I think the best way to achieve what you want is to use a proxy with DNS Spoofing.
Charles proxy does that but there might be other tools also.
One way(on the same lines as suggested by systho) I can think of is to make the api call directly using the IP and create a vhost on the server which is listening directly on a separate port.
This will work for me purely because of the fact that I have access to the servers hosting the web service.
I am running a MAMP server with default settings (port 8888) locally, and I have a Rails app running on its default port (3000).
In production, I will be having a Kentico server running that will need to run GET, POST and PUT requests via ajax to the Rails app.
Right now though, I am just wanting to set it up in a way so that locally I can develop this out without having to implement any form of CORS. Since POST and PUT requests are part of the mix, there's no way I can use JSONP.
Is there any way to do this, and if so will it translate to the same way of doing it once in production?
CORS would be the most standards compliant way of doing cross-domain communications. But other options include:
Set up a proxy server to proxy requests on the server-side to your Rails app
Use an iframe-based solution. This involves setting up a page on your server that makes same-domain XHR requests. You'd then include this page on the client-side using an iframe, and talk to it via inter-frame communication mechanisms such as postMessage.
Here's an overview of the latter technique: http://softwareas.com/cross-domain-communication-with-iframes
I am writing a ASP.Net MVC app that connects to a SQL database and uses existing C# libraries I have.
I also have a TCP server Windows application that sends/receives TCP messages via XML. I have successfully setup node.js and socket.io to handle all this and have a html page that sends/receives messages to the server. Node.js is serving up the html page at the moment. The XML is converted to JSON when sending/receiving data.
I am planning on setting my MVC app to serve the page up but was just wondering what your thoughts are on this use of cross framework setup. Does it seem viable and a good solution for handling TCP messages and sending it to the browser? I have also read about iisnode for hosting node in IIS which I guess would be a good idea for my setup. What are your thoughts on this?
You basically have two websites. One is your ASP.NET MVC website. and the other is a web client for your TCP windows application.
Since they are disjoint it will work fine.
You may want to have that web client's html server through ASP.NET MVC and only run a websocket server on node.js though. You may need to do some proxying to get the same origin to work.
If you server your HTML page from a webserver running IP Y, port X and then try to talk to the node.js websocket server running on IP Y, port X + n it may violate the same origin restriction.
This means your basically loading a socket.io client from server A and trying to talk to server B. The web page doesn't know you own both of these servers.
The solution would be a proxy, you proxy all requests to server A and B but since they all go through the proxy it doesnt violate the same origin.
As for proxy, nginx is one. There is a node-proxy. And IIS might be able to proxy it for you (Although I doubt IIS makes a good proxy)