How to add http2 to an nginx website

Change this:

listen 443 ssl;

to this:

listen 443 ssl http2;

Done… I wish all tech upgrades were this easy.

Code Tips

Golly Gosh Moments

You know that time you realized that you have been doing something the wrong way for a very long time and then finally realize the wrongness. For the sake of the low profanity rating of this blog, let’s call these golly gosh moments, although the Millennials might better understand #FML. Homer just says do’h.

So it’s just a normal day at the office, and I want to see if I can make an IP address lookup to get the approximate geo-location of a website visitor. I find an IP and it starts with 10 and turns out to be part of a private IP range. The next IP is the same. And the next.

To make a long story short, it turned out that we have been saving Heroku IP addresses in our logs instead of the user IP address for all our widget tracking for all of time. Heroku is a proxy, so the actual IP address is in an X-Forwarded-For header. For educational purposes here is how to make an express.js app behave better with a trusted proxy:

// App is an express.js app
app.enable('trust proxy');

// req.ip now contains the correct
// IP address during requests.

A one-liner made a world of difference for the logging. Golly Gosh.


The Notepad trick

There is a good reason Notepad has survived through all iterations of Windows. It is the best tool for clearing formatting!

For example, copying text from a webpage to Word will often keep the formatting (color, size and so on) but copying it to Notepad first and then re-copying it to the other editor clears the formatting completely.

I call this “The Notepad Trick” and I use it all the time so I thought it would be a good idea to pay homage to good ol’ Notepad.

Here is a direct copy between two Google Docs documents:

Google Docs copy text

Notice how the headline is the same size. Sometimes one might not want this. Here is the same copy with Notepad as a middle step:

Copy with Notepad as middle step

The formatting is all cleared, yay!

By the way, the trick is also described elsewhere.