Archive

Coding Bits

This post could also be titled “How to Set Up a Load Balancer in Front of Heroku” or “How to Set Up a Static IP Address on Heroku Without Add-ons.”

I work in East Africa, and data is fairly expensive for our users. A lot of telcos provide zero-ratings so that the owners of the service can choose to pay for the cost of the data instead of the users.

Zero-rating deals are typically scoped to a given IP address instead of a URL. If a service provider hosts a site onexample.com, which points to 12.34.56.78, they’ll need to arrange a zero-rating deal for 12.34.56.78.

We’re launching a new Web service on Heroku. I’d like to route traffic from a domain through to Heroku. Normally I’d follow Heroku’s Custom Domain Name guide, but because we’re providing zero-ratings I’ll need the client to interact with a specific IP address instead. My DNS needs to point to that specific IP address instead of to a Heroku subdomain.

I’m relatively new to networking, but after stumbling around for a while here’s what I set up.

I’m using HAProxy as a load balancer running on the server with the designated IP address. I set up SSL bridging following the HAproxy infrastructure layout guide.

haproxy_tls_bridging

The client accesses example.com, which resolves to the HAProxy server. The proxy forwards the request to Heroku, receives the response, and sends it back to the client.

Here are some specific configuration details:

  1. Create an A record in DNS pointing from your domain to the HAProxy server, which has your designated zero-rated IP address.

  2. Specify the HAProxy back-end to point to your app’s subdomain on Heroku:

  server MY-APP MY-APP.herokuapp.com ssl check cookie MY-APP.example.com sni req.hdr(Host)
  1. Meanwhile, on Heroku’s side, associate your subdomain with the app:
$ heroku domains:add MY-APP.example.com

And you’re done!

While debugging this system I noticed that my application code was issuing 301 Redirect responses when I hit MY-APP.example.com, sending me to MY-APP.herokuapp.com. I initially thought that this was a result of mis-configuring something, but it turned out that those redirects were being issued from application logic, not by HAProxy or Heroku (which doesn’t perform redirects).

Aside from that brief redirection confusion, this configuration has worked pretty well! It might also be useful if you’d like more fine-grained control when setting up your static IP address than you’d get from a paid Heroku add-on like QuotaStatic or Fixie.

An alternative implementation: It’s also possible to set up SSL pass-through. However, that requires giving your SSL certs to Heroku. Since I already had an ACM (automated certificate management) system, I wouldn’t have been able to auto-renew those certs on Heroku. And since I also already had a working HAProxy instance to build on, manually renewing certs for Heroku seemed more complicated than the solution presented above.

For a long time, I’d thought GIMP had bad support for tablets. Aside from feeling a lot of kinetic dissonance from the choppy feedback, I saw multiple mouse cursors. One cursor was from my laptop touch pad and another from my Wacom stylus. The two moved independently and stylus cursor disappeared every time I navigated away from the canvas.

double-cursor

I searched a lot for GIMP tablet configurations and Wacom drivers for Linux, but turns out it was a Wayland issue.

Gnome with Xorg solved everything!

Hope this helps whoever else stumbles across this.

I used to edit PDFs using GIMP. I would open the PDF in GIMP, make edits, export it as a .mng file, and convert it back.

$ convert -reverse pdf.mng pdf.pdf

This would work well except all the texts were rasterized.

I recently tried editing PDFs using LibreOffice Draw again and was delighted to discover its PDF editing capabilities have improved. Gonna use LibreOffice Draw from now on.

I learned about Insomnia from Vinay.

Insomnia makes sending REST requests really easy to manage, so you don’t have to store a whole bunch of curl commands.

It’s very similar to Postman (also an excellent requests manager).

Harry would probably tell me there’s an emacs mode for this.

I bet that emacs mode doesn’t have a punny name.