An open API service indexing awesome lists of open source software.

https://github.com/wnuqui/rack-app_version

Middleware that sets the version of an app via response header.
https://github.com/wnuqui/rack-app_version

app-version rack-middleware

Last synced: about 2 months ago
JSON representation

Middleware that sets the version of an app via response header.

Awesome Lists containing this project

README

          

# Rack::AppVersion Middleware
[![Build Status](https://wnuqui.semaphoreci.com/badges/rack-app_version/branches/master.svg?style=shields)](https://wnuqui.semaphoreci.com/projects/rack-app_version) [![SourceLevel](https://app.sourcelevel.io/github/wnuqui/rack-app_version.svg)](https://app.sourcelevel.io/github/wnuqui/rack-app_version)

`Rack::AppVersion` is a middleware that sets the version of an app (Rack compatible web applications) via response header.

## Setup

### 1. In your Gemfile

```ruby
gem 'rack-app_version'
```

### 2. In `config/application.rb` of your Rails application, put the code below.

```ruby
module YourApp
class Application < Rails::Application

# ...

config.middleware.use Rack::AppVersion

end
end
```

### 3. In `Rakefile` of your Rails application, put the code below.

```ruby
module Rack
class AppVersion
def self.generate_version
# Implement logic of getting application version here.
end
end
end

require 'rack/app_version/rake_task'
Rack::AppVersion.load_tasks
```

Doing `bundle exec rake -T | grep app_version` will give you the following which you can use:

```bash
rake app_version:generate # generate app version and write it in .app_version file
rake app_version:init # generate .app_version file that will contain application version
```

### 4. Use `have_app_version` matcher to ensure everything is setup (optional).

This rspec matcher can be used by the application to ensure that everything is properly configured.

```ruby
it 'has app version in response headers' do
expect(env).to have_app_version
end
```

## Common Gotchas

To determine where to put the `Rack::AppVersion` middleware in the Rack stack, run the following command:

```bash
bundle exec rake middleware
```

In many cases, the Rack stack will be different running in production environment. Run the following command to see the middleware stack in production:

```bash
RAILS_ENV=production bundle exec rake middleware
```

See The [Rails Guide to Rack](http://guides.rubyonrails.org/rails_on_rack.html) for more details on rack middlewares or watch the [railscast](http://railscasts.com/episodes/151-rack-middleware).