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


  • Quote of the Week: Leo Tolstoy

    “There is no greatness where simplicity, goodness, and truth are absent.” — Leo Tolstoy

  • I’ve been reviewing an old PowerPoint slide deck I have from Andy Hunt’s “Refactoring Your Wetware” talk. One of the slides covers the Dreyfus Model of Skill Aquisition, something that Andy and Dave Thomas also discuss in their “Herding Racehorses, Racing Sheep” talk (which you can see when the No Fluff, Just Stuff conference comes to your town, by the way).

    The whole concept is just fascinating to me. The model is made up of several “layers” or levels of proficiency in a given skill:

    1. Beginner
    2. Advanced Beginner
    3. Competent
    4. Proficient
    5. Expert

    Each level represents a different pattern of behavior, a different way of thinking. A learner will perceive the world differently at each level. For example, at the “Beginner” level, the learner is preoccupied not necessarily with learning something, but with simply accomplishing a task. Compare that to an “Expect” learner, who relies on intuition, not reason, to accomplish his goals.

    Forcing an expert to fit into a rules-based structure designed for a beginner ultimately makes the expert less productive and even downright miserable. On the flip side, placing a beginner in the intuitive environment that an expert thrives in can render the beginner incapable of doing anything. Yet both of these actions occur continually in the corporate world. Why is that?

    I don’t have any good answers yet, but Dreyfus surfaces some fascinating ideas. For a more thorough explanation of the model, read this entry from Dave’s blog or Google for “dreyfus model.”

  • Distance education posts moved to new blog

    In preparation for my NCHE workshop next week, I decided to move my distance education posts to a separate blog. Distance education is such a compelling new option for high school graduates that I felt it deserved its own dedicated space for posts. I’ll be making all of my new entries there so I encourage you to bookmark the page or add the feed to your RSS reader if you’d like to keep up with my future thoughts on this subject. I’d also love to hear your own thoughts about this unique method of earning a college degree.

  • Auto-completion of paths in Windows 2000

    I’m still using Windows 2000 on my desktop system at home (yeah, call me a dinosaur, I don’t care). One thing I’ve found annoying when switching between my desktop and my laptop that runs Windows XP is auto-completion of paths and filenames on the command line. In short, Win2K just doesn’t do it by default! A simple registry edit can magically change this, though. Just follow the instructions in this article and start tabbing.