• CORS woes on Heroku

    ,

    After spending the past 4 hours attempting to solve what boiled down to a rather simple problem, I figure I’d better blog about it to save someone else the time and effort.

    If you’ve been leveraging Passenger’s new –nginx-config-template command line option to add CORS headers to static assets served from a Rails app hosted on Heroku, and the CORS headers recently disappeared under mysterious circumstances… read on.

    I’ve been using the method described here to add CORS headers to custom fonts served from a Heroku-hosted Rails app that’s proxied by Nginx which handles serving static files. I recently updated to Rails 4.2.2 and suddenly, my custom fonts (.woff and .woff2 files) no longer had CORS headers on them.

    After the aforementioned hours spent scratching my head, I discovered that the latest version of the sprockets gem is generating asset digests that are 64 chars in length, where previously they had been 32. Nginx’s default regexp for identifying requests for static assets assumes the digest will be 32 chars long, like so:

    # Rails asset pipeline support.
    location ~ "^/assets/.+-[0-9a-f]{32}\..+" {
      error_page 490 = @static_asset;
      error_page 491 = @dynamic_request;
      recursive_error_pages on;</code>
    
      if (-f $request_filename) {
        return 490;
      }
      if (!-f $request_filename) {
        return 491;
      }
    }
    

    Changing the regexp to recognize digests that are 64 chars in length immediately solved the problem:

    location ~ "^/assets/.+-[0-9a-f]{64}\..+" {
       ...
    }
    

    I had to laugh after something so stupid and silly cost me a good chunk of my Saturday to debug. But at least it’s working now. My statically served custom fonts have the correct CORS headers and Chrome and Firefox are happy again.


Need help?

I’m an independent software developer available for consulting, contract work, or training. Contact me if you’re interested.


  • Discriminate against mice… use AutoHotkey

    Let’s face it, mice are slow. Mice are very slow. And mice cause bad things to happen to your wrist.

    Keyboards, on the other hand, are fast. And you barely have to move to get things done on them.

    Discriminate against mice. Use AutoHotkey.

    AutoHotkey is a free utility which allows you to define global hotkeys to do all sorts of nifty things. Using AutoHotkey scripts (which are outrageously easy to write) you can script everything from iTunes to your automated tests. For example, I currently have my system setup so that when I press Windows-G, a new browser window is opened and sent to Google. When I hit Windows-F9, a random image is selected from a specific folder and set as my Windows background. When I hit Windows-T, the automated test suite for the current product I’m testing is executed.

    Time savings? Yep. Less stress on your wrist? Absolutely. Big kewlness factor? Booyah.

    Visit AutoHotkey’s web site to download the utility. You can also visit the message board for free scripts which do all sorts of nice things. For example, I’ve found this iTunes script to be quite useful.

  • Ruby QuickRef

    Need a “cheat sheet” for Ruby? Check out Ruby QuickRef. An excellent place to go when you just can’t remember that funky little automatic variable containing the program args. (It’s $* by the way.)

  • Ham radio gets a wiki

    The web is really going places: ham radio operators now have their own wiki. Whoda thunkit?

    HamWiki’s goal is to serve as a conduit for more experienced hams (Elmers) to share practical information (both technical and non-technical) with newbie operators. I’m tickled pink, purple, and green to have this resource available now (although eHam.net has always been a useful resource).

    So how about it? I know of a couple other hams who are also computer geeks, but that’s about it. There’s plenty of room in the hobby for more enthusiasts, and a hobby dealing with AC reactance, antenna theory, and techniques of single-sideband modulation would seem to fit perfectly with the debate over statically versus dynamically typed languages

    The ARRL’s web site is the definitive source of information about the hobby. It’s so much more than just CB on steroids. The tests are quite easy to pass if you’re willing to do a little studying. There are also several active radio clubs in the local area (see RARS for one).

    The most immediate benefit, though, is that during North Carolina’s next ice storm, you’ll still be able to “phone home” even when your cell phone is rendered useless by power outages and falling towers.

    73s,
    Matt / AG4TS

  • From Wikipedia to Wikibooks

    Wikibooks is an online repository of textbooks that can be accessed, copied, edited, and distributed for free. Co-founder Jimmy Wales says that his service aims to make it possible to get the textbooks needed to study any subject (including software development) online for free.

    Read more…