rack-redirect 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.md +45 -0
- data/Rakefile +55 -0
- data/lib/rack-redirect.rb +32 -0
- metadata +68 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 http://atmos.org
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
rack-redirect
|
2
|
+
=============
|
3
|
+
More and more of my friends are deploying on [Engine Yard Solo][solo] and I
|
4
|
+
keep getting asked for help. My friends at [everlater][everlater] wanted every
|
5
|
+
incoming request for *.everlater.com to go to www.everlater.com. Here's a
|
6
|
+
little app that you can deploy on solo to handle all the weird HTTP_HOST
|
7
|
+
variants your app might 404 on.
|
8
|
+
|
9
|
+
Installation
|
10
|
+
============
|
11
|
+
|
12
|
+
% sudo gem install rack-redirect
|
13
|
+
|
14
|
+
Deployment
|
15
|
+
==========
|
16
|
+
Your rackup file should look something like this.
|
17
|
+
|
18
|
+
require 'rubygems'
|
19
|
+
require File.join(File.dirname(__FILE__), 'lib', 'rack-redirect')
|
20
|
+
|
21
|
+
use Rack::EY::Solo::DomainRedirect
|
22
|
+
run lambda { |env| [200, { 'Content-Type' => 'text/plain' }, ['Hello there, gorgeous'] ] }
|
23
|
+
|
24
|
+
testing
|
25
|
+
=======
|
26
|
+
|
27
|
+
Just run rake...
|
28
|
+
rack-redirect with a value of 'www'
|
29
|
+
- forwards on from http://www.example.org to the next app
|
30
|
+
- redirects from http://example.org to http://www.example.org/
|
31
|
+
- redirects from http://wwww.example.org to http://www.example.org/
|
32
|
+
- redirects from http://alpha.example.com to http://www.example.org/
|
33
|
+
- redirects from http://example.org/nate to http://www.example.org/nate
|
34
|
+
- redirects from http://example.org/nate?trip_id=42 to http://www.example.org/nate?trip_id=42
|
35
|
+
|
36
|
+
rack-redirect without specifying a prefix
|
37
|
+
- forwards on requests from http://example.org to the next app
|
38
|
+
- redirects from http://alpha.example.com to http://example.org/
|
39
|
+
- redirects from http://alpha.example.org/nate to http://example.org/nate
|
40
|
+
- redirects from http://alpha.example.org/nate?trip_id=42 to http://example.org/nate?trip_id=42
|
41
|
+
|
42
|
+
|
43
|
+
[sinatra]: http://www.sinatrarb.com
|
44
|
+
[everlater]: http://everlater.com
|
45
|
+
[solo]: http://engineyard.com/solo
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rubygems/specification'
|
4
|
+
require 'date'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
|
7
|
+
GEM = "rack-redirect"
|
8
|
+
GEM_VERSION = "0.0.3"
|
9
|
+
AUTHOR = "Corey Donohoe"
|
10
|
+
EMAIL = "atmos@atmos.org"
|
11
|
+
HOMEPAGE = "http://github.com/atmos/rack-redirect"
|
12
|
+
SUMMARY = "A gem that provides a simple example of rewrites in rack"
|
13
|
+
|
14
|
+
spec = Gem::Specification.new do |s|
|
15
|
+
s.name = GEM
|
16
|
+
s.version = GEM_VERSION
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
s.has_rdoc = true
|
19
|
+
s.extra_rdoc_files = ["README.md", "LICENSE"]
|
20
|
+
s.summary = SUMMARY
|
21
|
+
s.description = s.summary
|
22
|
+
s.author = AUTHOR
|
23
|
+
s.email = EMAIL
|
24
|
+
s.homepage = HOMEPAGE
|
25
|
+
|
26
|
+
s.add_dependency "rack"
|
27
|
+
|
28
|
+
s.require_path = 'lib'
|
29
|
+
s.autorequire = GEM
|
30
|
+
s.files = %w(LICENSE README.md Rakefile) + Dir.glob("{lib}/**/*")
|
31
|
+
end
|
32
|
+
|
33
|
+
task :default => :spec
|
34
|
+
|
35
|
+
desc "Run specs"
|
36
|
+
Spec::Rake::SpecTask.new do |t|
|
37
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
38
|
+
t.spec_opts = %w(-fs --color)
|
39
|
+
end
|
40
|
+
|
41
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
42
|
+
pkg.gem_spec = spec
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "install the gem locally"
|
46
|
+
task :install => [:package] do
|
47
|
+
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "create a gemspec file"
|
51
|
+
task :make_spec do
|
52
|
+
File.open("#{GEM}.gemspec", "w") do |file|
|
53
|
+
file.puts spec.to_ruby
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
module EY
|
5
|
+
module Solo
|
6
|
+
class DomainRedirect
|
7
|
+
attr_accessor :prefix
|
8
|
+
def initialize(app, &block)
|
9
|
+
@app = app
|
10
|
+
@prefix = nil
|
11
|
+
yield self if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
parts = env['SERVER_NAME'].split('.')
|
16
|
+
suffix, chunk, prefix = parts.pop, parts.pop, parts.pop
|
17
|
+
|
18
|
+
if prefix == @prefix
|
19
|
+
@app.call(env)
|
20
|
+
else
|
21
|
+
prefix = @prefix ? "#{@prefix}." : ''
|
22
|
+
destination = "#{env['rack.url_scheme']}://#{prefix}#{chunk}.#{suffix}"
|
23
|
+
destination << "#{env['PATH_INFO']}"
|
24
|
+
destination << "?#{env['QUERY_STRING']}" unless env['QUERY_STRING'].empty?
|
25
|
+
|
26
|
+
[301, {'Location' => destination}, ['See Ya!']]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-redirect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Corey Donohoe
|
8
|
+
autorequire: rack-redirect
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-31 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rack
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: A gem that provides a simple example of rewrites in rack
|
26
|
+
email: atmos@atmos.org
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.md
|
33
|
+
- LICENSE
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- lib/rack-redirect.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/atmos/rack-redirect
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.5
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: A gem that provides a simple example of rewrites in rack
|
67
|
+
test_files: []
|
68
|
+
|