A unique Twilio testing predicament - ruby-on-rails

I have a pretty unique predicament here. I'm using Twilio and need to test my Twiml response on my local machine. The goto solution for that is ngrok, but the problem is that the site I'm working on relies on subdomains for proper routing. There is no mysite.com, only sub.mysite.com. In the local environment I've modified hosts to redirect sub.mysite.dev to 127.0.0.1, but I haven't a clue how to solve this over a tunnel. Any thoughts?

I'm the creator of ngrok.
You can still make this work with ngrok, you'll just need to decide on a few subdomains up front that you want to use for testing. ngrok lets you forward multiple tunnels via the configuration file (https://ngrok.com/usage#config) Example configuration file:
tunnels:
one.mysite:
proto:
http: 80
two.mysite:
proto:
http: 80
three.mysite:
proto:
http: 80
This will forward
one.mysite.ngrok.com -> 127.0.0.1:80
two.mysite.ngrok.com -> 127.0.0.1:80
three.mysite.ngrok.com -> 127.0.0.1:80
It's not a wildcard (ngrok doesn't support wildcards at the moment), but having a few subdomains setup should be good enough for testing, I imagine.

Related

Testing Twilio with ngrok tunnel to localhost results in bad host name error

In the past I've used ngrok to test twilio webhooks on my local machine - it's always worked. I'm working on a new app that uses Co-Pilot (not sure if it has anything to do with co-pilot) and I'm getting the 11210 error: HTTP bad host name.
I initialize my tunnel with /Applications/ngrok http -host-header=rewrite local.whicheversiteimworkingon.com:80
The URL listed in the Message Text is http://fcd0ed57.ngrok.io/sms/twilio/incoming but the body shows
Twilio was unable to fetch content from: https://local.thesiteimworkingon.com/sms/twilio/incoming
Error: Unknown host local.thesiteimworkingon.com
Account SID: AC5a22f090b458f6942da879d347451dfd
SID: SM9c45741b5b70967df6a7e196e3bee552
Request ID: 9fde222c-14e1-448e-ad79-4a392d212ffd
Remote Host: local.thesiteimworkingon.com
Request Method: POST
Request URI: https://local.thesiteimworkingon.com/sms/twilio/incoming
SSL Version: TLSv1.2
URL Fragment: true
Unfortunately I don't have an example of this from when it was working - it's been months (maybe 12+) since I've had to do this.
[Update] I've confirmed this happens with co-pilot and regular numbers, starting to think it's environment related.
Have I misconfigured something in order to test this locally?
Can you try the https ngrok instead of http?
Twilio developer evangelist here.
It may be to do with the application server you are using expecting a different host name. When you start Ngrok, you can pass the --host-header flag to rewrite the host header for your application.
ngrok http 3000 --host-header=rewrite local.domain.com
Let me know if that helps at all.

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.

google OAuth for service on unusual port

I have running my own website for security reasons at an unusual port: https on Port 11223 instead oh 443.
This website provides the feature to login with an google account, realized by using the google OAuth API.
At the last step of authentication (redirecting back from google OAuth to my system), an network timeout happens.
On the other hand: if my server is running https on default port 443 instead of 11223, everything works fine.
I have configured the google OAuth client settings (Redirect URIs, Home page URL, JavaScript origins) for using the special port 112233. But without success.
Maybe it's important to know, the Server is behind a firewall with NAT. This means, the firewall receives https connections to port 11223 to redirect this to the internal webserver running https only on port 11223. But I think, this is not the point.
What could be the reason, why port 443 works but port 11223 doesn't.
I guess google OAuth does not support webservers running on an unusual prot!?!
The port number is 16 bits and thus can not exceed 65535.
Could it be proxy configuration issues? I recommend you configure your firewall to return 404 on the port 11223 and see what happens.

Requests through another machine

Is it possible to make requests for example with Savon through something like ssh-tunnel. I can run this stuff from my stage server whose IP is whitelisted in the service I'm sending requests to. But of course I want to do the development on my computer :P so is there any option to do that? I've already tried savon's proxy: option in many combinations such as
proxy: "http://name:password#my_stage_server.com"
etc. I'm using Ruby on Rails.
SSH tunnels are the way to go. They are easy to set up, use this in one terminal session:
ssh -L 8080:servicehost:80 myuser#stagingserver
Once established, leave it open. It'll open port 8080 on your localhost as a tunnel to the TCP service at host:443. Point savon to http://localhost:8080/some/url/to/service to access the service running on http://servicehost/some/url/to/service.
If you need this frequently, it's convenient to add it to your ssh config file, which is located at ~/.ssh/config. It's a plain text file, the example above would look like this:
Host staging
HostName hostname.domain
LocalForward 8080 servicehost:80
User myuser
With this configuration you can open the tunnel by simply issuing ssh staging. There are more options you could set, please refer to the MAN page for details.
Hostname resolution
Keep in mind that the hostname servicehost must be resolvable from your staging server, not your development machine. You can use IP addresses, too.

Serving Juggernaut 2 over pure HTTPS connection

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']
});

Resources