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


  • Setting speed dial numbers on a Sprint RAZR V3m

    I’ve been generally displeased with my Motorola RAZR. Sprint gave it to me over a year ago and aside from terribly poor battery life, it has one of the worst user interfaces I’ve ever seen on a phone. Despite that, it’s very compact and since my Sprint plan doesn’t expire until October of this year I’ve stuck with it.

    Something I couldn’t figure out was how to set the speed dial numbers. Turns out that there isn’t a way to do this through the main “Contacts” list (seems like that would be the best place for it). After Google failed to turn up anything, I began randomly clicking through my settings menu in frustration, attempting to locate the speed dial settings. I finally found them. Finally.

    Go to the main settings pane, then select the “Contacts” button (orange book with a phone icon on the front). There will be an entry on this menu titled “Speed Dial #s” which will let you configure everything you need. Why this wasn’t included on the main contact list I’ll never know, but there you have it.

  • Download an image file using wget

    wget -O filename.png "http://some.url/folder/some_image.png"
    

    And to upload the same file using Capistrano:

    task :something do
      put File.read("filename.png"), "#{deploy_to}/remote_filename.png"
    end
    
  • Key_read/uudecode failed when pulling from git

    I began getting a strange error message from git earlier this week:

    key_read: uudecode (random SSH key junk here)
     ssh-rsa (more random SSH key junk here)
     failed
    

    The error message only showed up when I ran git pull. Google didn’t find much to help me, but acting on a hunch I removed the IP address of my git repo from my known hosts. The error immediately went away.

    If you’re getting the same message, determine the IP address or domain name of your git repo. Search for those values in your ~/.ssh/known_hosts file and remove them. You should be good to go after that.

  • Career 2.0 at TriJUG tonight

    Has your career been a random product of your manager’s whims or company’s needs? Never rely on your company to keep your skills current and marketable. Take control of your own career with a proven strategy.

    Jared Richardson presents a talk titled “Career 2.0: Take Control of Your Life” at tonight’s Java Users Group meeting in RTP. If you’re curious about the book we’re working on, come on out. His talk will cover a lot of what we’re writing about. Pizza and networking at 6:30, talk starts at 7.