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


  • Come tipp some links with us

    Rails RumbleThe Rails Rumble took place this past weekend, and together with fellow raleigh.rb‘ers Mark Bennett and Nathaniel Talbott we formed a team. 48 hours, one go-cart race, and several Wii games later we finished our creation and dubbed it Link Tipping.

    Link Tipping is very similar to digg, except instead of voting on links you “tipp” them with real money. We integrated with Amazon’s new Flexible Payment Service to support micropayments: you can tipp in $0.25 increments. Once a link has received a tipp, the individual who created the resource at that link can log in, “claim” the tipps, and have the money transferred to his Amazon account.

    (No, I’m not misspelling “tip.” We intentionally spelled it “tipp” in the app.)

    The wonderful thing about Link Tipping is that, since real money is being used, the links that move to the top of the list are much more likely to be useful and remarkable.

    There were 90+ apps entered in the Rails Rumble and voting started yesterday. Check out the full list. Could these many apps have been built in this short an amount of time using a Java or .NET stack? I have my doubts. Rails isn’t a silver bullet, but it sure is fun to rumble with.

  • Water restrictions

    Raleigh, the city that I live in, recently implemented stage one water restrictions. This means I can water with a sprinkler once a week, and by hand with a hose twice a week.

    This simplifies my life. Whereas I once had to be concerned about watering every other day, now I only need to be concerned about watering once a week.

    Better yet, once my plants and grass die from lack of water, I won’t have to water at all. Thank you, City of Raleigh, for helping me simplify my schedule this way.

    sar-casm [sahr-kaz-uh-m] –noun “harsh or bitter derision or irony”

  • Slides from Chaotic Agility talk at Agile RTP

    These are the slides from the presentation I gave at the Agile RTP user group on August 7th. It was a great experience and I appreciate everyone showing up. The talk generated some good discussion.

    I was hoping to post these sooner. Sorry for the delay. I look forward to seeing you all again at the Agile RTP meetup in September.

  • Testing with Selenium at the raleigh.rb meetup tonight

    Here’s your friendly reminder that the next raleigh.rb meetup is TONIGHT! Brenton Leanhardt will be introducing us to the wonders of testing our Ruby apps with Selenium. Get yourself a full description of the talk and directions to Red Hat on the Meetup page.

    I think it’s safe to say that if you’re a Ruby programmer in the Triangle area and aren’t a regular attendee of raleigh.rb, you are greatly missing out. Join us tonight at the most happenin’ Ruby bash in Raleigh and redeem yourself!