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


  • Growth in Ruby jobs relative to Java

    This is one of the reasons I’m doing mostly Rails consulting right now.

  • Trouble purchasing iPod Touch January update

    I was initially quite irritated with Apple for choosing to charge existing iPod Touch users like myself a $20 bill to get a hold of their January update. I’m still a bit ticked since it seems quite unfair to punish the early adopters like this, but by last Tuesday I had decided to push past my annoyance and plunk down the $20 for the update.

    Now I can’t seem to purchase it for some reason.

    When I visit the iTunes store or Apple’s web site and click on the link to buy the update, I get sent to a page with information about the update and a single OK button. I click OK and get sent back to the iTunes store home page. Every. Single. Time.

    I’ve called Apple a couple of times on this. They say it’s a bug on their end and that they’re working on it, but they can’t seem to give me an estimated resolution time. Apparently, this problem is only being experienced by a few lucky people, like myself.

    Has Apple lost a sale? Possibly. I want to give them my $20, but they just don’t seem to want it that badly. I may opt to use the 1.1.3 jailbreak instead (when it becomes available for the Touch).

    And I was really looking forward to using the “official” apps…

  • Quote of the Week: George Orwell

    “Whoever controls the image and information of the past determines what and how future generations will think; whoever controls the information and images of the present determines how those same people will view the past.” — George Orwell

  • Locking a nation into permanent childhood

    America’s education system is majorly messed up. The disturbing thing is the intentionality with which it’s being destroyed, coupled with the ignorance of most parents to what’s really going on:

    … American schooling was taken over, in the late 19th century, by statists enamored of the Prussian compulsion model, aiming to create a docile peasant class by crippling the American intellect — making reading seem real hard, for starters, by replacing the old system in which delighted kids learned to combine the sounds of the Roman letters, with a perverted “whole word” method better suited to decoding hieroglyphics.

    If God blesses me with a family, I’ll be homeschooling my kids. I only hope it’s still legal by that time.

    Read the full article.