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.
- Host: GitHub
- URL: https://github.com/wnuqui/rack-app_version
- Owner: wnuqui
- License: mit
- Created: 2017-07-12T13:53:58.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-11-21T04:36:53.000Z (over 5 years ago)
- Last Synced: 2025-12-27T01:36:22.583Z (6 months ago)
- Topics: app-version, rack-middleware
- Language: Ruby
- Homepage:
- Size: 23.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Rack::AppVersion Middleware
[](https://wnuqui.semaphoreci.com/projects/rack-app_version) [](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).