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


  • Installing Mongrel on a shared host

    Can this be true? Could it really work? I think I’ll find out.

  • Fitting words

    From the biography of John Henry Jowett:

    “We leave our places of worship, and no deep and inexpressible wonder sits upon our faces. We can sing these lilting melodies, and when we go out into the street our faces are one with the faces of those who have left the theater and the music halls. There is nothing about us to suggest that we have been looking at anything stupendous and overwhelming. Far back in my boyhood I remember an old saint telling me that after some services he liked to make his way home alone, by quiet by-ways, so that the hush of the Almighty might remain on his awed and prostrate soul. That is the element we are losing, and its loss is one of the measure of our poverty, and the primary secret of inefficient life and service.”

  • RubyConf 2006: Day 3

    The last day of RubyConf is now almost over. It was a seriously great conference. As I mentioned previously, I’ve never been to a RubyConf before so I didn’t know what to expect. I’m glad I went. It was great hanging out with some seriously smart people. Several of the presentations went clear over my head. Several were quite entertaining. Most were incredibly intriguing. The Google Summer of Code talks were all excellent. Nice job, guys. It’s great hearing about what other folks are working on. Not only does it make me want to dig into their code, it also makes me want to keep hacking on my own projects. David, Chad, and Rich, thanks so much for coordinating this. It was a blast.

    Oh, and before I forget, yes, I do have more pics. Actually, MANY more pics. But they’ll have to wait. I’m in Lousville, it’s late, I’m tired, and I’m on vacation. If you’re lucky, maybe I’ll post these once I get back to Raleigh. And I don’t want any questions about why I’m not using Flickr and tagging them, by the way. This is the way I like doing it, and just like Matz is the benevolent dictator of Ruby, I am the benevolent dictator of my blog. Well, maybe not dictator. King, maybe. President. CEO.

  • RubyConf 2006: Day 2

    The second day of RubyConf 2006 dawned with snow on the ground. This isn’t unusual for Denver in late October, but it’s special to me since snow is a much rarer element in North Carolina, even in mid-January. The talks have been fascinating so far. Some have been more relevant to me than others, of course. Nathaniel gave his talk a couple of hours ago, drawing parallels between the way Ruby was built and the way businesses (such as Terralien) can/should be built.

    Matz answered questions from the audience last night. Here’s a pic:

    RubyConf 2006 Matz

    Here’s another pic showing what the crowd looked like last night:

    RubyConf 2006 Crowd

    Due to where I was sitting, this reflects about 75% of the room. In case you were wondering, yes, the hotel is swarming with geeks. I’ll have another update and more pics coming tomorrow, hopefully.