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


  • Indieconf 2012: The Simple Logic of SEO

    I enjoy listening to Pepper talk. She’s a very practical and no-nonesense kind of person. Her session on SEO did not disappoint. She outlined a basic but surprisingly powerful approach to a task that is widely considered to be incredibly complex.

    There are 3 players in SEO: the people, the search engine, and the web site owners (us). Our responsibility is to offer people what they want on the pages they search. If we do this successfully, the search engines (okay, Google) will naturally rank us higher. Our goal should be to provide useful information to people, as opposed to simply trying to get millions of hits.

    There are several tools that can help us measure the success of our information sharing:

    The goal is to find out what people are looking for, and tweak our sites to offer this to them. Pepper explained that most people organize their sites in a similar way: home page, services page, blog, etc. Instead, she recommends “flipping the triangle” and creating keyword-rich landing pages that target the specific topics users are searching for.

    Also keep in mind that Google doesn’t scan keyword meta tags. Instead it relies on:

    • Title meta tag (should include keyword phrases)
    • Description meta tag (140 chars max)
    • Domain URL (to separate words use hyphens, not underscores)

    She recommends reading In the Plex by Steven Levy for a better understanding of how Google thinks.

    Tomorrow I’ll recap one of my favorite presentations at the conf, “The Anatomy of a Freelancer” by David Rogers.

    This post is one in a series from Indieconf 2012

  • Indieconf 2012: How to Form Good Habits and Break Bad Ones

    James Clear gave the first talk I attended on Saturday morning. It was all about good and bad habits and how we can form and break them. When it comes to habits we can’t rely on willpower alone. It generally fails us. Instead, James explained how we can use the 3 R’s, reminders, routines, and rewards, to shape our habits in a positive way.

    Keys to creating a good habit:

    • tie it to a current behavior
    • keep it as simple as possible
    • reverse the response (celebrate rather than suffer)

    Keys to breaking a bad habit:

    • understand what causes it (why did it start?)
    • understand why we do it (what is the reward?)
    • create a new routine that results in the same reward

    James then explained how tht 3 R’s of personal habits hold true for the business of freelancing as well:

    • “We think we decide our life, but it’s often designed for us.”
    • “We design customer behaviors whether we want to or not.”
    • “Customer decisions are guided by the information they are sent.”

    He recommended two books for further learning: “The Power of Habit” by Charles Duhigg and “Switch” by the Heath Bros. He also recommends stickK, an app that uses a rather unique approach to helping us set and meet our goals.

    Tomorrow I’ll share what I learned from Pepper Oldziey’s talk titled “The Simple Logic of SEO.”

    This post is one in a series from Indieconf 2012

  • Indieconf 2012 recap

    Indieconf 2012

    Indieconf 2012 happened this past Saturday at the McKimmon Center in Raleigh. I’ve attended every indieconf for the past 3 years and this was by far the best yet. Michael Kimsal does an incredible job of recruiting speakers and organizing a full day of thought provoking presentations. I really don’t know how he does it all. He must be superhuman or something.

    I didn’t regret attending any of the 7 talks I went to. That’s unusual. Even at some of the best conferences I’ve attended like RubyConf or BizConf, there were always at least a couple of talks that I didn’t find very useful. That wasn’t the situation at indieconf. Over the next few days I’ll be posting some useful takeaways from each talk so stay tuned.

    This post is one in a series from Indieconf 2012

  • App.net Roster goes live

    App.net is an exciting new alternative to Twitter. It’s perfect for those of us who would rather not be subjected to an endless stream of advertising. It feels like Twitter did years ago, except better because the nominal monthly fee keeps out the riffraff.

    The creators of App.net also place a special emphasis on fostering a thriving developer community. I think this is absolutely the right approach to take if their goal is to build a reliable and useful communication platform that doesn’t become annoyingly over-commercialized and frustratingly limited the way Twitter has.

    My own contribution to the ecosystem recently went live: App.net Roster lets you embed a slick, App.net-backed roster to your web page by simply copying and pasting a few lines of HTML. It’s a great way to let your web site visitors see what you and your friends are talking about on App.net.

    App.net Roster was forked from Twit Roster and is a 100% database-free Sinatra app hosted on Heroku. Check it out and let me know what you think.