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


  • I got tagged by my friend Jared Richardson on Wednesday. Now I’m supposed to blog about five things that people don’t know about me. Oh joy. I have to actually do some thinking? This might hurt.

    1. I’ve lived in seven different states over my 25 years of existence. I’ve visited 30 states. No, my father wasn’t in the military. It’s just worked out that way for some reason. I can’t say I’ve particularly enjoyed all the hopping around, but it sure gave me a chance to see a wide variety of scenery and discover how people differ between regions.
    2. My ambition going into college was to become an astronaut. Yes, I’m serious. My plan was to get a masters in Computer Engineering, learn Russian, get my pilot’s license, and move to Houston. Then I discovered that the computer programming I had been doing since I was 9 was actually kind of enjoyable. Funny how circumstances and chance occurrences can have such a dramatic impact on carefully laid plans.
    3. Shortly after I moved to North Carolina, I spent eight months apprenticing at Ken Auer’s software studio in Holly Springs. There I was given the opportunity to learn XP (eXtreme Programming) and pair program with true masters of the craft of software development. The skills I picked up there have been immeasurably valuable to me ever since. Ken has been influencing the direction of XP since it was founded. Aside from getting to learn from him, being at the studio also gave me the chance to meet guys like Andy Hunt, Nathaniel Talbott, Duff O’Melia, and Adam Williams… all during my first year of college.
    4. My first computer was a PC Junior. I was writing text-based adventure games in BASIC on it when I was 9. I still have one of the games I wrote. The code is definitely not DRY, but the game is fun to play.
    5. I was taught completely at home from K through 12, along with my only brother. It’s an experience that I look back on with an incredible amount of appreciation. I’m grateful that my parents (especially my Mom) decided to go this route. They both could have just stuck us in a government school so they could accumulate money and things (like too many people choose to do these days), but they chose to invest themselves in us instead. It was a decision that has paid off in many ways, not least of which is a closer relationship between me, my parents, and my brother.

    There you have it. Still awake? Good. I thought of a few more things I wanted to add to the list (such as “single and looking”) but it just didn’t seem like the right thing to do. Now I’ll tag Nathaniel Talbott, Adam Williams, John W. Long, Alan Hoffler, and Sri Sankaran.

  • AppleScript via Ruby

    Nice to see Ruby getting some attention on a non-Ruby blog.

  • Andy Hunt crashes raleigh.rb tonight

    Andy Hunt will be speaking at the Raleigh-area Ruby Brigade meetup tonight. It’s sure to be a good show, so grab a fellow geek and head on down to Red Hat headquarters at 7 PM. Signs will direct you to the correct room. Also, if you want an even bigger helping of Ruby tonight, join us at 5:30 PM at Baja Burrito for our traditional round of pre-meeting chow and conversation.

  • Integrate GTD with Gmail using Firefox

    Getting Things Done is a book by David Allen. The methodology from the book, commonly referred to as GTD, has become quite popular inside certain tech circles. I’ve been using GTD for roughly a year now. I can’t claim to be an expert at it, but it’s helped me stay organized during a period of my life that would otherwise have been extremely unorganized.

    There are many tools out there that make implementing GTD on your computer fairly painless. For you fellow Mac cultists, Actiontastic does the job nicely with a clean, minimalist interface. There is also Tracks, a Rails-based web application that you can install… well, pretty much wherever. What I’d like to introduce in this post, though, is a unique Firefox extension called GTDGmail.

    GTDGmailI’ve been using GTDGmail for a few months now. Once installed, it integrates with Gmail and modifies your view slightly. Among other things, it divides your tags into four categories: projects, contexts, statuses, and references. As e-mail messages come in, you can categorize them as actions by tagging them with the “Action” status. If an e-mail contains important information you’d like to keep for future reference, tag it with a “Reference” and a “Project.” As you tag your e-mail, it becomes available under GTDGmail’s pre-built search links that appear above your tags.

    You can also send yourself actions and references. This is where the famous GTD practice of “capturing” comes into play. The idea is to get all that stuff floating around in your head out and organized into action items. Sending yourself an action or a reference results in a new e-mail message in your inbox, automatically tagges as an action or a reference and ready to be organized further into projects and contexts.

    GTDGmail also has some handy non-GTD uses. For example, it makes regular tagging much easier by placing links at the top of each e-mail, one link for each tag. Simply click on a link to add that tag to the e-mail you’re currently viewing. Click the red X next to the tag to remove it from the e-mail. This is much faster than scrolling through a drop-down to find the tag you want to add or remove.

    The only downside to GTDGmail is that it does make Gmail less responsive. Since GTDGmail has to overlay Gmail’s existing layout with additional information, it can get bogged down at times. However, the upside of being able to immediately categorize your incoming e-mail into action items more than makes up for this. GTDGmail is not for everyone, but I encourage you to try it out to see if it fits your own organizational style.