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


  • Streamlined turns 0.9

    The latest and greatest version of Streamlined was released a few weeks ago. Lots of new features and bug fixes are included in this release, including a handy (and fully configurable) breadcrumb trail implemented in part by yours truly.

    For those who aren’t familiar with it, Streamlined is sort of like Rails scaffolding on steroids. It lets you quickly and declaratively setup an interface for your ActiveRecord models.

    I continue to be amazed by the amount of code I don’t have to write when I’m using Streamlined. In fact, it’s starting to warp me. Whenever I work on a standard Rails project now, I inevitably begin asking myself why I’m having to write all of these actions to do basic CRUD stuff. Streamlined provides it for free.

    Streamlined is quickly approaching a 1.0 release (hopefully this month) so there has never been a better time to jump onboard. One good way to get rolling is with this post that I made a few months ago.

  • $100 laptop debuts this November

    Watch the inimitable David Pogue for a nice demo. OLPC’s $100 laptop debuts in the U.S. during a two-week window in November. It’s a buy one, get one deal. $400 sends one laptop to a poor kid in a third world country, and one laptop to you.

    Am I getting in on this deal? You betcha. Consider the hackability factor here. Pogue already snuck in a reference to Python in his video. Imagine the cool things that can be done with this device once Ruby is running on it. Not to mention the fact that it’s pretty indestructible.

    An extra $200 to send one to a needy child? What a deal. Count me in. What about you?

  • Quote of the Week: J. Boyd Nicholson

    “The gospel is not a tranquilizer for worried weaklings to help them sleep at night.

    “It is not a mass of dead dogmas, deep frozen in some ancient cathedral to be carried as a burden through life and thawed out five minutes before death.

    “The gospel is not a list of religious rules and regulations to be strung around the soul like a lucky charm in case of accidents.

    “No, the gospel of our Lord Jesus Christ is a message — and what a message! It is a living message from the living God for living people, just like us, for people with sins just like us, for people with sorrows and heartaches just like us.

    “It is the only message on the face of the earth with concrete promises and absolute assurances of an eternal inheritance that will withstand the impact of death and the collapse of the universe.”

    — J. Boyd Nicholson

  • As a Christian who is socially conservative, fiscally libertarian, and non-interventionist, I’m having a very difficult time imagining myself actually voting for any of the current Republican Presidential candidates. I’m just hearing the same old thing from all of them. All except one, who happens to be the only guy up there actually willing to tick off a few people while articulating his principals. That guy is Ron Paul.

    I agree with the premise of this article, namely, that Ron Paul is the only Republican candidate who has a chance of beating Hillary in 2008.

    What’s really cool is how Ron Paul is taking advantage of the Internet to promote his message. As of today, he has over 44,000 Meetup members. There are literally dozens of Ron Paul-related video clips on YouTube. And why shouldn’t there be? The mainstream media is only giving coverage to the perceived frontrunners of both parties, who spout the same drivel day after day.

    The Internet levels the playing field and de-monopolizes the television networks and newspapers. Even Google has hosted a one-hour Q&A session with Ron Paul. The Internet makes free speech free again. That’s why the efforts of many in our government to regulate the Internet should be aggresively opposed.

    Whether you’re liberal or conservative, you have to admit that Ron Paul speaks his mind and has a solid track record of constitutionlist voting. He’s a statesman in a political environment that harbors far too few.