Created
May 20, 2009 11:44
-
-
Save darashi/114761 to your computer and use it in GitHub Desktop.
add X-Git-Commit header to Rack application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rack middleware to insert git commit id into http response header | |
# For Rails, put this script under RAILS_ROOT/config/initializers | |
module Rack | |
class GitCommitHeader | |
def initialize(app) | |
@app = app | |
c = `git rev-parse HEAD`.chomp | |
@commit = (c =~ /^[0-9a-f]{40}$/) ? c : nil | |
end | |
def call(env) | |
status, headers, body = @app.call(env) | |
headers['X-Git-Commit'] = @commit if @commit | |
[status, headers, body] | |
end | |
end | |
end | |
ActionController::Dispatcher.middleware.use Rack::GitCommitHeader rescue nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment