• 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.


  • NFJS in RTP this weekend

    Two acronyms in one title! How much wilder can it get?

    I’ll be attending the No Fluff, Just Stuff conference in RTP this coming weekend (June 9th, 10th, and 11th). I attended my first NFJS last year and it was a truly memorable experience. I’m seriously looking forward to attending again this year. Aside from being packed with great speakers, NFJS events are always a fantastic way to hobnob with fellow geeks. I mean, these folks are passionate about what they do. Who else would give up their weekends to go talk about computer software?

    If you read my blog, I’d love to chat with you in person. I can’t read minds, though, so if you see a guy with my name on his tag by all means walk up and introduce yourself! I’m not mean. Really, I’m not.

  • Life on TV just isn’t fair

    This is a hilarious example of communication gone horribly wrong. Poor guy!

    There are two things I like about this. First, the cab driver does an outstanding job of improvising in a tight situation. He should get a medal. Second, the interview didn’t turn out that bad, at least when compared with lots of other interviews I’ve seen.

    Sure, the guy talked a lot while saying very little, but how is that different from what most other interviewees do? If you know you’re going to be on TV, take a few hours and come up with some points you’d like to make, then take those points and figure out what kinds of words you’ll need to put together to make them coherent. It’s time consuming, maybe even difficult, but it will provide immesurably more value to your audience than showing up unprepared.

    What about those of us who don’t get interviewed on the BBC? Why not strive for more effective dinnertime conversations, or delivery of a thought-provoking and entertaining presentation at work? For the geeks in our midst, consider making that comment in your code just a tad more concise, or ironing out that requirement a little more.

    “Speak properly, and in as few words as you can, but always plainly; for the end of speech is not ostentation, but to be understood.” — William Penn

  • Of satellite photos and real estate values

    Zillow.com is amazing. Enter an address, street name, or neighborhood name and you’ll be presented with a scrolling satellite photo of the area (a la Google Maps). Hover over a house and its current market value will be displayed. Spooky.

  • Excerpts from NFJS Anthology

    No Fluff, Just Stuff (NFJS for short) is a symposium / conference / geekfest that began touring a few years ago. This year, an NFJS Anthology containing articles from many of the top speakers is being published by the Prag Prog guys. A couple of sample articles have been published as free PDFs.

    The first article is by Stuart Halloway and covers how Spring uses Dependency Injection and Aspect Oriented Programming in a delightful marriage of DRY-bashing goodness.

    The second article is by Glenn Vanderburg and is called “Buried Treasure.” Why is the software development field going backwards? Glenn explains why in this excellent treatise on why old is not bad.

    I highly recommend reading both of these samplers because they contain a lot of useful information in their own right. Not having reviewed the entire Anthology yet I can’t vouch for the other articles, but given some of the names listed here (Eitan Suez, Venkat Subramaniam, Neal Ford, Jared Richardson) there probably isn’t much of a question over whether it’s good material or not!