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


  • Audible frequencies and cell phones

    Some of my co-workers were chatting at lunch yesterday about the highest audible frequencies that can be heard by people of various ages. Apparently, teens these days are programming their cell phones to use high frequency ring tones while in class. The frequencies are so high that adults can’t hear them, only teens can. One of my co-workers located a web site that has links to sounds at various frequencies. What’s the highest frequency you can hear? I got up to 18k using my headphones, but only 17k on my speakers. Anything higher than that makes me physically uncomfortable even though I can’t hear anything.

  • Bring on NFJS day 2

    It’s the morning of NFJS day 2 and I’m psyched about another day of listening to great speakers and hobnobbing with fellow members of geekdom.

    Yesterday’s kick-off was great. The first workshop I attended was Stuart Halloway’s intro to the Spring framework. This was mostly for review since I’ve used Spring before. Well worth the time spent to attend. Next up, Venkat Subramaniam’s talk on refactoring. Again, great stuff. I appreciated how he didn’t recommend memorizing a list of possible refactorings, but going with your gut on what you thought would make the program simpler and cleaner. The last workshop I attended was Raminvas Ladddd’s discussion of strategies for testing web applications. He touched on a few other frameworks, but his focus was on the open-source Selenium tool.

    The day closed with an excellent dinner and the keynote address from Dave Thomas which was cleverly titled “Cargo Cults and Angry Monkeys.” If you have a chance to hear this keynote at another NFJS, I’d certainly recommend it. It was fascinating and quite funny too!

  • 10 flagrant grammar mistakes that make you look stupid

    ZDNet UK recently published a list of common grammar mistakes that occur in e-mail messages. This isn’t something I’ve seen very much of from my friends and business associates, but every now and then an item from this list will sneak into a blog entry or an e-mail.

    I realize I’m just as serious an offender as everyone else, but I still thought I’d share this article with y’all. It was a helpful reminder to me of just how important correct grammar can be, especially in business communications.

    Now don’t go using no bad grammer anymore, okay?

  • NFJS Expert Panel podcast

    I noticed today that the NFJS web site now has a podcast. One of the audio clips available is the entire Expert Panel session from the New England NFJS in March. I’ve started listening and it’s quite good. In fact, it’s making me hungry for more great discussion at the RTP NFJS this weekend. Oops, excuse me. I need to wipe that drool off my keyboard.