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


  • Another record-setting Ruby meetup

    Last night’s meeting of the Raleigh-area Ruby Brigade set another record for attendance: 44 by Nathaniel’s count. This is 14 more than last month’s meeting. Incredible!

    This was another first for the group in that we were meeting at Red Hat’s headquarters on NC State’s centennial campus instead of our old location at the Brier Creek Panera Bread. This is the same building that BarCamp was held in a few months ago. It’s a VERY nice facility. Open wi-fi, convenient restrooms, and a red motif that goes nicely with the whole Ruby thing.

    Last night’s presentation was given by Stuart Halloway and Justin Ghetland. They introduced their new Streamlined framework to the group, which can be described as scaffolding on steroids. Maybe that’s too simplistic, though. I saw their original demo at RailsConf in June, but they were able to go into more detail tonight which was nice.

    Nathaniel made several announcements before the presentation began:

    • There is a Southeastern Regional Ruby Conference in the works. More information to follow soon.
    • A Ruby hacking night is being organized. This will probably take place once a month on Wednesday at our old meeting location, Panera Bread.
    • The raleigh.rb mailing list is the happenin’ place to be. Join up!

    What, you say you’re not a member of the Brigade yet? There is no excuse not to be. Sign yourself up and start hobnobbing with the ever-growing crowd of local Rubyists.

  • Review of “Mastering Guerrilla Marketing”

    I recently finished reading Mastering Guerrilla Marketing by Jay Conrad Levinson, author of the popular Guerrilla Marketing series. It was a good read. The book was broken up into 12 chapters and about 100 individually-numbered sections, each containing information about a certain aspect of guerrilla marketing. Topics ranged from planning to online marketing to technology to economizing.

    Levinson’s plan makes sense to me, but the organization of the book didn’t. Each numbered section didn’t have any kind of descriptive header, so I had to guess at what topic the section would focus on. Levinson’s instructions for creating a guerrilla marketing plan weren’t very instructional. They didn’t follow a logical, step-by-step pattern. This is more of an idea book than anything else, but the ideas he has are very good.

    One quote that I found particularly encouraging is this:

    There is no need to hit a home run the first time you’re at bat. A single will do, then another single, then another, one following the other — none grandiose, but each bringing you closer to your goal.

    Speaking for myself, I’m in “single hitting mode” right now. I’m almost to first base and will shortly be setting my eyes on second and digging in.

    If you’re looking for specific tips on marketing your business, look for a different book. If you like big-picture ideas, are wondering how to put the customer first as you market, and want some encouragement in your new business venture, it would be worth your time to check out Mastering Guerrilla Marketing.

  • Learn CruiseControl in three minutes

    Paul Duvall of NFJS fame just posted an excellent three-minute video demonstrating how to download, install, and use CruiseControl for Java. Having used both CruiseControl and CruiseControl.NET, I can say that this is one of the most concise tutorials I’ve seen for a geek who already knows his stuff, but needs a few hints to help him along. Check it out.

  • How does one handle busy days?

    My new consulting business, Adeptware, is in its second month and today I got slammed. Phone calls and e-mails with potential clients, a trip to the bank to get my new DBA forms copied for my accounts, an evening planning session with the calendar, installation of a new domain name and web site for a client, etc. My rhetorical question is this: how does one handle such days? A day with barely any time to breathe. A day in which I’m happy to have new business, but wondering how to fit it all on my calendar. I don’t expect an answer. Tomorrow will most likely be dead, except for the Ruby Meetup which I’m hoping will be packed again like it was last month. I’m beginning to think that’s just the way it goes for us self-employed chaps.