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


  • Thursday’s Ruby meetup was a huge success

    Last Thursday’s meeting of the Raleigh-area Ruby Brigade (also known as raleigh.rb, the Ruby Meetup, or the Ruby User’s Group… take your pick) was a huge success. A record-breaking 30 Rubyists were in attendance. Whether that was due to RailsConf or whether it was just a freak occurrence, I don’t know. What I do know is that it was a remarkable experience being part of a group that filled an entire room at Panera Bread.

    Nathaniel Talbott, the founder of the group, was out of town and had asked that I run the meeting. Little did I know what I was in for. Fortunately, there were plenty of RailsConf attendees there who had interesting stories to share. Lots of folks hung around to chat afterwards too. As a direct result of the meetup, I’ve given Mongrel a try and must say that I am very impressed with this well behaved dog. Let’s hope I stay that way.

    You say you live in the Triangle area and aren’t a member of raleigh.rb yet? Sacrilege! Sign yourself up right away. We meet once a month at the Panera Bread at Brier Creek, though the location very well may have to change given the attendance we had this last time around. (This is a good thing.)

  • Quote of the Week: Frederick Douglass

    “Find out just what any people will quietly submit to and you have found out the exact measure of injustice and wrong which will be imposed upon them.” — Frederick Douglass

  • I’ve gone independent

    Yes, I’ve left SAS, the world’s largest privately held software company. What would make me do such a thing? There were many factors involved in the decision, of course, but the primary reason was the opportunity to work full-time with Ruby on Rails from home. This will give me more time with my family. I’m also looking forward to doing more writing, speaking, and volunteering during the remainder of the year. Leaving was a difficult decision because I’ve enjoyed my last three years at SAS very much, but I’ve been wanting to get into independent consulting for over a year now. When the opportunity came up last month, I felt led to take it.

    My primary purpose in making this post was not to cast for offers, but I do want folks to know that I’m available now. My specialties are Ruby, Rails, Java, .NET, and PHP. I’m interested in using these technologies to develop world-class applications, especially web-based applications. I also have a passion for testing and continuous integration. I’m interested in helping development teams build and install automated testing frameworks and continuous integration servers. My background in agile development processes makes these interests a good fit.

    I’m not sure what the future holds for me in this area, but the freedom I’ve experienced so far is incredible. I know this is where God wants me right now. I’m looking forward to enhancing my development skills and branching out into new specializations. I’ve always enjoyed learning (due in large part, I think, to my background as a home schooled student) and now I’ve been given the chance to do so on a level I wasn’t able to before. What an adventure!

  • Whatever happened to a kid-safe Fourth?

    I remember when the Fourth of July was a family friendly holiday. It doesn’t seem to be kid-safe anymore judging from what I saw last night.

    My family opted to stay home yesterday instead of fight the crowds to see live fireworks. Our plan was to watch the fireworks display at Boston Harbor that is televised each year. Last year’s display was truly spectacular. Leading up to the main event, a live orchestra played a number of patriotic favorites. The orchestra then accompanied the fireworks as they went off. The display lasted for well over twenty minutes. Wonderful stuff to see, even on a low definition 27″ color Panasonic.

    This year was somewhat different. In addition to the Boston Pops, several pop and country musicians were hanging around to “do their thing” every now and then. In other words, they rendered butchered versions of our favorite songs using electric guitars and drums. The entire event was hosted by Dr. Phil (why him, I wonder?) and some other lady I didn’t recognize.

    The sad part was when the fireworks started. The orchestra would play a wonderful patriotic song for a few minutes, then a rock song would come on over the loudspeakers. The music kept switching back and forth between the good stuff and the junk. This was quite annoying because we had to keep muting the junk. What was even more annoying was that our television displays closed captions when the volume is muted. This meant we had to read the lyrics of these songs as the fireworks were going off. (Have you ever tried NOT reading closed captioning on a TV? It’s very difficult!) Judging from the lyrics (some of which were quite horrid) the songs had very little to do with the Fourth of July or fireworks in general. Go figure. If there had been young kids in the house who could read, we wouldn’t have been able to watch the show at all.

    I now wonder how long it will take before such televised fireworks displays are accompanied exclusively by rock music. When will the network execs finally decide that their sophisticated audiences shouldn’t be subjected to any more of these traditional patriotic tunes and would prefer to be serenaded by the “melodious” strains of Aerosmith and Garth Brooks?

    Is it normal for me to want to hear traditional music on the Fourth of July, or am I just a crazy old-fashioned American boy?