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


  • iPhone development

    Full Stack iPhone DevelopmentFor the past few months, I’ve been exploring the fascinating world of iPhone development. I have several application ideas and am working pretty hard on getting something to market. My first app will be free, though I hope to work up to a level where I can develop a solid paid app eventually. I’m enjoying learning Objective-C. It’s a mind bender in a lot of ways. Having to handle memory usage, for example. That gets annoying pretty quickly.

    My timing has been good since Terralien just launched its own full-stack iPhone development service last week. I’ve enjoyed developing solid Rails-based APIs for iPhones to interact with. I’m looking forward to flexing the skills I’m building on new projects. Learning is fun. The only difficulty is finding the time to learn everything I want to. It’s a never-ending pursuit.

  • I’m participating in the 2010 Walk for Life this month to support Pregnancy Support Services of Wake Forest. The walk is a family-friendly event that raises awareness and funding for the center. The cool thing is that you don’t need to walk or even live in Wake Forest to support the center. You can help by sponsoring me as a walker. It’s quick and easy to do. (There is more information about the center and what you would be supporting on my walker page.) Thanks so much for your help!

  • Federal makes it right

    A $25 check from Federal showed up in the mail yesterday. That more than covers the cost of a new box. It’s always nice when a company makes things right for their customers. I intend to continue buying their products since I know they’ll take care of me.

    Time Warner Cable: are you reading this? Learn something, please.

  • Hinkey Federal .40 S&W round

    Hinkey RoundI was enjoying an IDPA match at the Durham County Wildlife Club this past Tuesday evening and, aside from it being pretty cold, I had a great time. Except at the end of the fourth stage.

    I was almost through my first mag when I experienced a failure-to-fire. The round had fed properly and the slide appeared to be fully closed, but all I got when I squeezed the trigger on my Glock 23 was… nothing. No click. Just… nothing. I racked the slide again to eject the unfired round and I was able to finish the stage, but it cost me at least 2 seconds, perhaps more.

    After retrieving my ejected round, I noticed it looked a bit odd. Comparing it to another round, I discovered the rear of the case hadn’t been trimmed properly. It was a few millimeters too long, as you can clearly see in the photo I’ve posted here. My guess is that it prevented the slide from fully engaging. This is the first time I’ve seen anything like this, and talking with a few other shooters at the match, this was the first time they had seen anything like this either. Cool!

    I’ve sent the questionable round to Federal’s service department to see what they have to say. Hopefully they’ll make things right. The delay ended up costing me first place in the Novice class. What did I learn from this? First, that even quality factory ammo shouldn’t be relied upon to function flawlessly every time. Malfunctions will occur. Practice for them. Second, that every malfunction is different. I’ve practiced my failure-to-feed drill pretty consistently, but running into a situation where the slide closed and the trigger didn’t even click was something I just wasn’t expecting. Instead of treating it like any other failure, I let my surprise delay me from taking action.

    Final note: I’ve been extremely happy with Federal ammo thus far and would be surprised if they don’t make this right for me. This post wasn’t intended to criticize their company in any way, it was just a fascinating occurrence that I thought might interest others as well. Has anyone else seen a factory round that was too long like this?