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


  • Practices of an Agile Developer

    Practices of an Agile DeveloperI recently had the honor of reviewing the Pragmatic Programmers’ latest work of art, Venkat Subramaniam and Andy Hunt’s Practices of an Agile Developer. The book doesn’t ship until March 1st, but I would certainly consider adding it to my Amazon.com wish list now, especially if I were new to agile programming or wanted to promote agile practices within my team. It was refreshing to read such a concise, yet comprehensive overview of what agility is.

    The book covers all the major agile practices (and several of the not-so-major ones) including minimizing up-front design, being honest even when it hurts, practicing iterative development, writing tests, letting customers make business decisions, integrating continuously, and being a mentor. The focus is not on a single agile methodology like eXtreme Programming or Scrum, but on the practices common to all of these methodologies.

    One thing I really liked about this book was that it was split up into 2 to 3 page “chunks” of information. (If you’ve read Chad Fowler’s My Job Went to India, you’ll know what I’m talking about.) Such “iterative” writing makes it much easier for busy geeks to digest. I’m not forced to maintain an excessive amount of context between reads.

    Another thing I liked about this book was that it wasn’t dogmatic in its approach to agility. While reading, I didn’t feel that the practices were being crammed down my throat. Venkat and Andy did a good job of espousing the benefits of the practices without becoming preachy. This is an exceptionally good thing considering how difficult it can be to explain to “traditionalists” that agility can actually help, not hinder, the craft of software development.

    Venkat and Andy’s creativity really shows with their “angel and demon” motif which is used throughout the book. At the beginning of each section, a demon tells you what the typical response to a common software development problem is. At the end of the section, an angel gives you a brief overview of the agile practice which was covered and why it’s so much better than what the demon tempted you to do.

    If you’re new to agile development and want a good overview of what it’s all about, I highly recommend this book. If you’re an experienced agile developer and want a handy dictionary of common practices to refer to or push into the hands of a fellow developer who comes knocking, I highly recommend this book. If you’re fed up with the way software development is done and want to know some practical steps you can take today to begin programming more intelligently, I highly recommend this book.

    Most importantly, if you’re passionate about creating software and want to be encouraged to continue striving for excellence in everything that relates to it, this book will give you the boost you need.

  • Google Reader Beta

    I enjoy RSS feeds. Nay, I adore RSS feeds. So you can understand my consternation at having to maintain three sets of subscriptions on my work computer, home computer, and personal laptop. The lists never seem to be in synch. What a pain!

    I discovered the solution to my problem last week. It came in the form of Google Reader, a beta version, but nonetheless still a (mostly) functional online news reader with a delicious user interface. Now all my RSS feeds are stored in one place and I can access them from any computer in the world without installing SharpReader or Attensa. (And Google knows just that much more about me.)

    Now if Google would just get with it and add a calendar…

  • The Bridge Home Theater

    Yet another example of someone who has way too much time on his hands.

  • Red Letter: The Ruby Journal

    Another new Ruby e-zine is getting started. Joining Artima’s Ruby Code & Style is Red Letter: The Ruby Journal. They are currently searching for writing contributions of all types and sizes, and the most important part is that they’ll pay you for what you contribute. Column-length stories start at $350. Ruby, writing, and money? I’m all there.