Skip to content

Instantly share code, notes, and snippets.

@HoyaBoya
Created March 15, 2016 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HoyaBoya/79b8b1e3ce56fd24e7a0 to your computer and use it in GitHub Desktop.
Save HoyaBoya/79b8b1e3ce56fd24e7a0 to your computer and use it in GitHub Desktop.
module Middleware
class VersionEndpoint
def initialize(app)
@app = app
end
def call(env)
# Return the latest git-sha in ENV if the request is exactly the version endpoint.
if env['PATH_INFO'] == '/version'
if version = source_version
[200, {'Content-Type' => 'text/plain'}, [version]]
else
[404, {}, ['Not Found']]
end
else
@app.call(env)
end
end
##
# Easier to test.
def source_version
ENV['SOURCE_VERSION']
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment