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


  • Cleaning up on the web with AJAX

    Forbes.com hops on the AJAX bandwagon with a brief overview of what some new businesses are using it for. I found the point at the end about AJAX impacting Nielsen/NetRatings statistics particularly interesting.

  • Decoding COM HRESULT error codes

    As I mentioned in a previous post, I’m currently slogging through the melancholic mire of testing .NET/C# code. In the process, I’ve been receiving exceptions which give an HRESULT code in hex (i.e. 8×80020005) and not much else. That got me to wondering what these HRESULTs are and how to decode them. This wondering led me in turn to this page which has an excellent overview of what HRESULTs are and why they matter. I also uncovered a link to a freeware tool called HR Plus which can decode HRESULTs and give you a (usually helpful, sometimes vague) idea of what they mean. Both the page and the tool have been extremely handy to have around. I hope they prove handy for you too.

  • Vanderburg on building teams for Rails

    Glenn Vanderburg’s latest blog entry is a good one. Much of what he says can be applied to building teams for XP as well. XP is awesome and I really enjoyed my days on an XP team, but it takes discipline from each developer to make it work.

  • Eclipse, Visual Studio, and Ward Cunningham

    As Rich Main blogged in mid-October, Ward Cunningham recently left Microsoft for a job at the Eclipse Foundation. I found this especially fascinating considering that, after over 4 years of developing with Java, a job change recently required me to begin using C# for automated testing. The pain of doing so has surprised me.

    For some odd reason, I assumed that a product like Visual Studio made by a giant like Microsoft (and with a whopping $350+ price tag) would be at least comparable to, if not superior to, Eclipse (which, of course, is free). I was woefully incorrect. Some of the best features of Eclipse, such as auto-refactoring, are just not available. Other features have been implemented, but in a castrated form. It’s almost as if Visual Studio tries too hard to make things easy to do, and in the process destroys a great deal of the flexibility which made Eclipse so pleasant to use.

    After using Visual Studio for a week or so, I gave up on it and have switched back to Eclipse and an open-source C# plugin which I found. The plugin offers syntax highlighting and not much else, so I’m essentially writing C# in a souped-up version of Notepad, but it’s still better than trying to make my way around VS. Maybe I just haven’t inculcated the Microsoft way of doing things yet, but I’ll take Eclipse and Java back any day. I’m sure Visual Studio is useful in many cases, but for writing automated tests against APIs it just stinks.

    Ward must feel the same way.