• 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: J.R.R. Tolkien

    “It does not do to leave a live dragon out of your calculations, if you live near him.” — J.R.R. Tolkien

  • If it’s not your problem, whose is it?

    My friend, Alan, made a post on his blog yesterday that hit a nerve for me. The gist of it is that an unnamed airline left a friend’s bag out in the pouring rain by accident, then when asked if they would replace the bag and its contents basically said, “It’s not our problem.”

    Who is ultimately responsible for any customer interaction gone bad? I like this quote from the post:

    The boss is responsible. The cashier who faces the customer is responsible. The person who sends the email is responsible. The interface point is what the customer (or employee) sees, not the organizational structure behind the activity.

    There have been many times when I’ve gone through similar situations at local stores. Oh, I haven’t been told directly that “it’s not our problem,” but I’ve seen indications that the cashier or floor manager I’m speaking with doesn’t really care about me and probably wishes I would just go away.

    True customer service seems to be a rare thing these days, and getting rarer all the time. There is a huge market out there for businesses that will treat their customers with honesty and integrity. It’s just not that common anymore.

    Read the full story on Alan’s blog.

  • How to avoid skipping BarCamp

    July 22nd’s BarCamp RDU has come and gone, and wouldn’t you know I missed it? I was signed up to attend, but about a week prior to the event I learned I would be occupied that Saturday, and so I had to skip the most exciting geekfest to grace RDU since June’s NFJS. What a devastating shame.

    My only hope is that there will be one next year. Judging from the press generated by the event, that seems likely. Take this RedOrbit article, for example. There are a slew of other articles that have been published as well. Visit the official BarCamp site for the complete list.

    One comfort is that I can at least pseudo-participate by browsing Flickr for photos tagged with “barcamprdu.” I’ve stumbled across a few familiar faces this way. Incidentally, I know what the title of my session will be next year: “How to Avoid Skipping BarCamp”

  • Face the music, parents

    wndcommentary.jpg

    News flash: What teens watch, listen to and read affects their thinking and behavior. Sound common-sensical? In years gone by, it was. But today, in our increasingly permissive culture, otherwise well-intentioned parents often ignore the obvious.

    My brother is a columnist and regularly writes for WorldNetDaily. His latest article details the results from a recently published Rand Corporation survey indicating that adolescents who listen to large quantities of music containing improper messages about sexuality end up engaging in such activity much more frequently.

    Read the article on WorldNetDaily