Created
March 15, 2016 19:04
-
-
Save HoyaBoya/79b8b1e3ce56fd24e7a0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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