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


  • Ken Auer at the Agile RTP meeting tonight

    Ken Auer (of RoleModel Software and XP fame) will be speaking at the Agile RTP meeting here in Raleigh tonight. I used to work at RMS and am interested in hearing Ken’s take on agile methods once again. The year I spent at his studio was some of the best personal growth time I’ve ever experienced. If you’re in the area, swing by Frankie’s at Brier Creek tonight to join us!

  • Lone Star Ruby Conf now accepting proposals

    For those of you interested in a trip to sunny Austin, the Lone Star Ruby Conf is now accepting speaker proposals. LSRC is a regional conference similar to the Ruby Hoedown that’s coming to Raleigh in August. It’s great to see these regional conferences taking off.

  • Getting started with Streamlined (part 1)

    If you were one of the unfortunate souls who missed RailsConf this year, I’m sorry for you. If you happened to be at RailsConf but missed Justin Gehtland’s excellent Streamlined tutorial then you are truly of all people most pitiable.

    On a more serious note, the tutorial was very good and has sparked a lot of interesting ideas for further enhancing Streamlined beyond its already hefty feature set. For those who don’t know, Streamlined is a Rails plugin that brings the declarative goodness of ActiveRecord to the UI. It enhances your views with full-featured scaffolds that include relationship management, quick adding of associated models, and much more.

    If you haven’t played with Streamlined before, why not give it a try? With several fresh screencasts over at the blog, a bundle of new documentation, a new sample project, and version 1.0 on the horizon… there’s no time like the present.

    Getting started with Streamlined is easy…

    (more…)

  • Speaking at NCHE again this year

    For the homeschoolers who read my blog, I’ll be speaking at the North Carolinians for Home Education (NCHE) state conference in Winston-Salem again this year. I’m giving my distance education talk on Saturday, May 26th, from 12:30 to 1:30 PM in South Main 3. A few of the points I’ll cover include:

    • Why distance education is a good alternative to traditional college for homeschool graduates
    • How I earned my own four-year degree through distance education
    • Which colleges currently offer distance education and how to choose wisely from among them
    • An overview of the different methods that can be used to earn credit through distance education (portfolio review, CLEP, etc.)

    There will be a few surprises too! I hope to see you there.