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


  • Soapadoo now reads my blog

    My friend Duff’s latest enhancement to Soapadoo is so totally excellent that I thought I should blog about it. In addition to being the premiere source for reviews of anything, Soapadoo can now read your blog and detect when you’ve posted a review. Soapadoo will then syndicate that review itself, saving you the trouble of posting it twice. This will be immediately useful to me as I’ve already double posted several reviews here and on Soapadoo. Why not check out Duff’s announcement and get your own blog hooked up?

  • Quote of the Week: Michael Crichton

    “A window of opportunity will not open itself.” — Michael Crichton

  • Teascript opens for beta testing next week

    Teascript is my latest Rails application. It’s scheduled to go live in mid-September. You can read more about it in the original announcement that I posted a few weeks ago.

    Beta testing for Teascript begins next week. I’m looking for a dozen or so people to help sanity check the application before I unleash it on the public. (I already have 8 signed up.) As a beta tester, you would receive full access to the product starting early next week.

    While I’m not requiring anyone who volunteers as a tester to send me feedback, it’s much appreciated! Interested? Shoot me an e-mail at matthew AT teascript DOT com and I’ll add you to the list.

  • E-mail shouldn’t be this hard

    Yes, it’s time for another Microsoft rant. If you’re a regular reader of my blog, you’ll know that these rants are usually quite justified (unlike some others I’ve read).

    How long should it take to create an e-mail template? Go ahead, take a guess. Five minutes? Ten minutes? Twenty?

    Try 45 solid minutes!

    Before I sat down, I thought to myself, “Self, how hard can it be to create a template in Outlook 2000? Sure, it’s older software, but it’s Microsoft, right? Made for the average computer user.”

    Whatever. I gave up and had to just copy and paste my layout into a new e-mail. I suppose I’ll have to do this each time I need to use this particular design. Very frustrating. It seems that the deeper into Outlook you dig, the worse the user interface gets and the less things make sense. I found some VERY wacky things in there under the templating and forms menus. Quite frightening.

    This makes me want to switch to a different e-mail client. Any suggestions?