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


  • Distance education workshop at this year’s NCHE convention

    I’m excited to announce that I’ll be giving a workshop on distance education at this year’s NCHE conference. (NCHE stands for North Carolinians for Home Education; my brother and I were both home schooled K-12 and were members of the group at one point.)

    The workshop is titled “Distance Education: An Alternative to Traditional College.” In it, I’ll be sharing the story of my own experience earning a four-year degree in Computer Science via distance education. I’ll also be sharing the many benefits distance education offers over traditional college, as well as providing some pragmatic steps that parents and high schoolers can take to find a good distance education program and succeed in it.

    My reason for posting is two-fold. First, I want to let you, my readers, know about the conference in case some of you might want to attend. For a description of the workshop and more information about the conference, visit the conference web page.

    Second, and most importantly, I plan on sharing the URL of my blog during the workshop so folks can visit, ask any follow-up questions that they might have, and possibly even use a discussion board (I’m considering adding one to this site). I’ll be continuing to post about distance education and its role in today’s economy over the next few months for those who are interested in the topic.

    If anyone has any immediate questions or comments, feel free to post a comment here. I’d also enjoy hearing from you if you plan on attending any workshops at this year’s conference.

  • No more Rover when searching

    For months, I’ve been annoyed by that little dog, Rover, that appears when performing a file search in Windows XP. He’s slow, he’s cute, and I just want him to go away. Fortunately, I found out how to send him packing back to the doghouse today. Click on “Change Preferences” in the search sidebar, then click “Without An Animated Character.” Rover will obligingly leave.

    Why Microsoft would choose to set up Rover as the default search character in an operating system they call Windows XP Professional is beyond me.

  • Quote of the Week: Paul Johnson

    “My idea of being rich — or at least of feeling rich — is to have no debts, mortgage, or overdraft and to be able to pay all bills by return post. This may seem a fairly modest ambition, but if everyone in the West were in this position our societies would indeed merit the term affluent, and the world would be a much happier place.” — Paul Johnson, British historian and author

  • Lottery Tickets

    I live in North Carolina and our new state-sponsored gambling program… I mean, our new lottery… opens today. At work, I’ve already overheard several hallway conversations in which lottery ticket purchases were mentioned. For my fellow North Carolinians who are considering a purchase, just remember that a dollar can buy you a tasty hamburger at McDonald’s. Oh, and burning your money will at least keep you warm.

    “Common sense is just as good a critic of the lottery as any statistical breakdown.” — Hunter Baker