Skip to content

Instantly share code, notes, and snippets.

@whoisjake
Created October 14, 2009 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whoisjake/210408 to your computer and use it in GitHub Desktop.
Save whoisjake/210408 to your computer and use it in GitHub Desktop.
My first entry for coderack.org
module Rack
# A rack middleware for wrapping sites in http://kanyelicious.appspot.com/.
class Kanye
def initialize(app)
@app = app
end
def call(env)
request_uri = env['REQUEST_URI']
# Check if kanye=true exists, remove param, and stop
if (/kanye=true/ =~ request_uri)
env['REQUEST_URI'].gsub!("&kanye=true","")
@app.call(env)
else
request_uri += ((request_uri.include?("?")) ? "&" : "?") + "kanye=true"
full_request = "http://" + env['HTTP_HOST'] + request_uri
# Otherwise redirect
[302, {'Location' => "http://kanyelicious.appspot.com/" + full_request }, ['Redirecting...']]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment