0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
This Rack middleware allows you to run specific apps when the request domain matches a given filter. The filter can be provided in a number of ways, for example as a regex or as a string.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 1.5
 Project Readme

Rack::Domain

Build Status Gem Version Coverage Status Inline docs

Rack::Domain is a Rack middleware that enables you to intercept a request with a specific domain or subdomain (or regexp that matches a domain, actually) and route it to a specific application.

Installation

Add this line to your application's Gemfile:

gem 'rack-domain'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-domain

Usage

Rack::Domain supports three kinds of filters in order to match a domain.

  • A string: it will match only if the string is exactly the same as the domain.
  • A regexp: it will match if the domain matches the regexp.
  • An array of strings and regexps: it will match if at least one of the elements of the array matches (as described above) the domain.

To decide where to dispatch the request if there's a match, you can use an existing Rack app through the :run option, or you can pass a block in which you can use the classic use|run|map... syntax. This works because the block is directly passed to a new instance of Rack::Builder.

Examples

Using a regexp:

# Match the 'lobster' subdomain.
use Rack::Domain, /^lobster\./, run: Rack::Lobster.new

Using a string:

# Match only if the current domain is github.com:
use Rack::Domain, 'github.com', run: MyGitHubClone

Using an array of strings and regexps:

use Rack::Domain, ['lobst.er', /^lobster\./], run: Rack::Lobster.new

Using an on-the-fly app build with a Rack::Builder-style block:

use Rack::Domain, /^api/ do
  use Rack::Logger
  run MyApi
end

Contributing

Fork, make changes, commit, open Pull Request, be awesome! Read the GitHub guide to forking if you don't know how to.

Also, issues are more than welcome! Open one if you find a bug, you have a suggestion or simply to ask a question.