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


  • What’s with the new theme?

    You may have noticed that I’ve changed my blog’s theme again. Why, you ask? Why persist in this maddening switching of graphics and templates? Simply that I haven’t found the ideal layout yet. I’m hoping that this new theme will be something I can stay with long-term. I really like it. The dual sidebars are wonderful because they give me more room to post information. The theme is widget-enabled, it’s fairly pretty, and it seems pretty logically organized to me. What do you all think? Keep it or trash it?

  • Social bookmarking with BlinkList

    I admit it: I’ve been rather slow getting on the social networking bandwagon. When it comes to things that other people like, I just don’t care. If someone in my circle of friends or colleagues recommends something (through the joy that is Soapadoo, for example) then I’ll take notice, but advice from total strangers just doesn’t strike me as being very trustworthy.

    That being said, I discovered de.licio.us and BlinkList over the weekend and was immediately hooked. On BlinkList, that is. Why not de.liciou.us?

    1. Multi-word tags aren’t supported.
    2. It’s drop-dead ugly.
    3. Typing the URL is torturous.

    I imported my existing bookmarks (about a bazillion of ’em) into BlinkList on Monday. I’ve been shocked at how useful the service has been since then.

    • Pages can be bookmarked instantly. Whenever I see a page I want to keep, I hit my “Blink It!” button, type in a few tags, hit submit, and I’m back to the original page and surfing away. The entry barrier for creating a bookmark just got a lot lower for me. (I haven’t yet decided if this is good or bad.)
    • Bookmarks can be tagged. This allows me to esentially store bookmarks in multiple folders. This makes sense because any given bookmark can’t be narrowed down into a single category.
    • I can exchange bookmarks with my friends. Odds are that if one of my friends has a site bookmarked, I’ll probably want that site bookmarked too. One click and it’s done.
    • I can access my bookmarks anywhere. Whether I’m hanging upside down off a cliff in New Zealand or fleeing a grizzly bear in the Canadian Rockies (not that I’ve ever done either of those things)… I can still view and edit my bookmarks.

    Want to see BlinkList in action? Check out my bookmarks. If you’re a stranger then I can’t promise they’ll be interesting, but at least you’ll be able to check your stocks before you lose your grip on that cliff edge.

  • Quote of the Week: G.K. Chesterton

    “It is necessary to have in hand a truth to judge modern philosophies rapidly; and it is necessary to judge them very rapidly before they dissapear.” — G.K. Chesterton

  • Introducing Teascript

    Teascript is a Rails-based web application I’ve been working on for about a month. It’s targeted towards home school parents and students who need to design a high school transcript with minimum fuss.

    Traditionally, this process has been quite involved. My own parents and I designed my transcript using an Excel spreadsheet. It was painstakingly slow! Many home school books have transcript templates in them, but again, the process of photocopying and filling them out is time consuming.

    It is because of this that I decided to create Teascript. The application is still under development, but I have put up a teaser page highlighting some of its features. The page also allows you to sign-up to receive notification when Teascript goes live sometime later this year.