Serving Juggernaut 2 over pure HTTPS connection - ruby-on-rails

I have a Ruby on Rails website at which I force all connections to be SSL. I need all connections from that site to use HTTPS as well. Also, Google Chrome will automatically switch to HTTPS even if I connect to another port.
This means that I cannot connect to
http://www.mysite.com:8080
I have to serve the juggernaut js file over https. But that doesn't work since Juggernaut doesn't want to use https instead of http at its internal webserver. So I copied the application.js file from the juggernaut folder /usr/local/lib/node_modules/juggernaut/public/application.js into my rails folder public/juggernaut and changed the following line in my HTML code:
to
Now I seem to be able to at least initiate a Juggernaut object. The problem arises when I start to actually do some listening. I get this error:
Not found: https://www.mysite.com:8080/socket.io/1/?t=1340749304426&jsonp=0
So either I need to
a) be able to change it so I can actually have Juggernauts webserver use https instead of http. This is preferable.
or
b1) fix Juggernaut so it doesn't try to access socket.io over port 8080 and
b2) add socket.io to my server, preferably under the www.mysite.com/juggernaut folder instead of the root.
Any ideas?
Thanks!

Might be a little late but I was able to get it to work using this. (My juggernaut is hosted on heroku)
var jug = new Juggernaut({
secure: true,
host: 'yourHostHere',
port: 443,
transports: ['xhr-polling','jsonp-polling']
});

Related

Serving localhost rails application externally https

I am currently running a rails application on my local machine as the backend api for a hobby web application (have too many sql rows and dont want to pay for it).
I already figured out how to forward my port and access the api through http://[myexternalipaddress]:8080/api/etc.... from the external internet.
This is working fine, but i want to be able to serve this end point through https instead so my users dont get security warnings. I did some research, but I am confused what I need to do next. Is the https serving done via my rails configuration, or some other method?
here is the command I use to start my rails server:
rails s --binding=0.0.0.0 -p 8080
You can use ngrok and expose your local server
on mac you can install it with brew
$ brew cask install ngrok
$ ngrok http 3000
this will give you url like https://xxyyzz.ngrok.io to access it publicly

What does it mean to run a local web server?

I can program and develop in Ruby on Rails/JS/HTML/CSS to make a full stack app. However, there are holes in my understanding of the HTTP request/response cycle. Are the following points correct?
If I make a Rails app, and on the command line type rails server I get a local server, which I can make requests to. If I open a browser, type localhost:3000, and press enter, I am making an HTTP request to the local server.
Rails uses by default a web server called WEBrick, though there are others like Thin, Puma, and Unicorn. These are all pieces of software, and what makes them web servers is the fact that the software implements functionality to process HTTP requests.
When I run a local web server, it means that my computer is running one of these pieces of software that listen for HTTP requests.
Is the above what it means "to run a local web server"?
I have seen other examples of ways to "run a local web server". One of the is to run npm install -g http-server in a project directory, and then navigate to localhost:8080. Is this also just software that starts running and accepts HTTP requests on port 8080?
On a Ruby command line, install rack gem: gem install rack. Then in a new Ruby file we require 'rack', start a web server:
Rack::Server.start({ app: MySimpleApp, port: 3000 })
We can then define a web application MySimpleApp that is rack-compliant (object that responds to call method):
class MySimpleApp
def self.call
(...)
end
end
So now when we navigate in our browser to localhost:3000, MySimpleApp is executed. Is rack simply running it's default WEBrick server? Is what the above commands do simply run a local web server and define what to do when an HTTP request comes in (execute MySimpleApp)?
You're pretty much right on your understanding there. HTTP is just a text-based protocol that, like many, operates over TCP/IP.
The built-in WEBrick server isn't the best example of an HTTP server written in Ruby, but it's included for legacy reasons because it's often "good enough" to get you started. Pow is considerably better and despite being produced by the same company that produced Rails it's largely written in Node.
The beauty of HTTP, like a lot of internet based protocols, is it doesn't matter what language you use so long as you comply with the standard.
Rack is a layer that operates behind HTTP and provides a thin layer of abstraction on the request/response cycle.
A server is something that opens up a port (80, 443, 8080) for some sort of data transfer. Port 80 is the HTTP port and port 443 is the HTTPS port. 8080 is a commonly used port for development (as is 3000). https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
A local server by definition is a server running on your machine.
Overall, you are definitely on the right track.

Rails Https redirect to http

I have hosted my website http://www.example.com, and it works fine.
when I try to access it by https://www.example.com, my browser says it is unable to connect?
Is this normal? (Is it a DNS issue or a rails app)
This probably isn't a Rails issue, but it's hard to say without more information. The most likely explanation is that your server probably isn't configured to have port 443 open, which is the default port for https connections.
If you are on Amazon EC2, you'll need to manually open port 443 in the EC2 security group configuration.

Juggernaut on a https website

I'm trying to use Juggernaut 2 on a website that uses HTTPS. I don't need Juggernaut itself to use https per se.
So, I'm trying to load the required application.js from Juggernaut's own webserver at port 8080 through http in the layout of my rails app.
That works fine.
Then I notice Juggernaut trying to read socket.io from port 8080 through https, and ofcourse failing since it's own webserver uses http and not https.
So I either need to make Juggernaut's own webserver at 8080 use https or I need to get juggernaut to load everything it needs from port 8080 through http.
I could ofcourse locate its application.js and hardcode http usage in there, but is there a better way to solve this ?
With some searching I found this solution:
<script type="text/javascript" charset="utf-8">
var jug = new Juggernaut({protocol: 'http', host: 'www.mysite.com', port: '8080', secure: false});
</script>
This will let Juggernaut load socket.io through the host,protocol and port that you specify.
You could also host the socket.io and juggernaut js file on your own site and reference them that way through https.
That way your users won't have warnings about insecure content on a secure site.
The downside of course is that you will need to keep them up to date them whenever you upgrade juggernaut.

How to proxy files from firewalled server through rails application

I have a rails application running on Nginx which needs to serve files for download from another internal server. The internal server uses a dynamic url to generate the file for download, so it isn't a static file sitting in a folder. Both the rails server and server with the files are on the same LAN but only the rails server is open to the public on port 80.
Additionally the files that I'm wanting to serve are anywhere from 5GB - 200GB so I don't want to tie up the rails process for the whole download if that is possible. Is there a way to do this with Net::HTTP + send_data? Or perhaps some kind of Nginx proxy rule?
From inside the LAN you can download a file with a url like this:
http://username:password#192.168.0.5/export?uuid=1234567890
The problem is 1) there is no access control for that url, with the user / pass you can download any file you want by passing in it's uuid parameter and 2) the server is only LAN accessible.
I figured out the answer to this question by following the tutorial here: http://kovyrin.net/2010/07/24/nginx-fu-x-accel-redirect-remote/
To handle the HTTP Basic authentication you need to add this line to your nginx config:
proxy_set_header Authorization "Basic BASE64_USER_PASS";
Where BASE64_USER_PASS is a base64 string of your username and password in the format "user:pass"

Resources