Browse files

Initial Commit

  • Loading branch information...
0 parents commit 8e8d88839017d0a9df708a9e6f530c1a2afbefc8 @hassox committed Nov 21, 2009
22 .gitignore
@@ -0,0 +1,22 @@
+.DS_Store
+log/*
+tmp/*
+TAGS
+*~
+.#*
+schema/schema.rb
+schema/*_structure.sql
+schema/*.sqlite3
+schema/*.sqlite
+schema/*.db
+*.sqlite
+*.sqlite3
+*.db
+src/*
+.hgignore
+.hg/*
+.svn/*
+gems/gems/*/
+gems/specifications/*
+!gems/gems/thor*/
+!gems/specifications/thor*
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 <YOUR NAME HERE>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7 README
@@ -0,0 +1,7 @@
+= proxy_stack
+
+Description goes here.
+
+== Copyright
+
+Copyright (c) 2009 <YOUR NAME HERE>. See LICENSE for details.
56 Rakefile
@@ -0,0 +1,56 @@
+require 'rubygems'
+require 'rake'
+require 'pancake'
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "proxy_stack"
+ gem.summary = %Q{Simple Light weight proxy}
+ gem.email = "has.sox@gmail.com"
+ gem.homepage = "http://github.com/hassox/proxy_stack"
+ gem.authors = ["Daniel Neighman"]
+ gem.add_dependency "pancake", ">=0.1.23"
+ gem.files = FileList["[A-Z]*", "pancake.init", "{lib,spec,rails}/**/*"]
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+ end
+
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
+end
+
+require File.join(File.dirname(__FILE__), "lib", "proxy_stack")
+Pancake.root = Pancake.get_root(__FILE__, "lib", "proxy_stack")
+THIS_STACK = ProxyStack
+ProxyStack.load_rake_tasks!(:master => true)
+
+require 'spec/rake/spectask'
+Spec::Rake::SpecTask.new(:spec) do |spec|
+ spec.libs << 'lib' << 'spec'
+ spec.spec_files = FileList['spec/**/*_spec.rb']
+end
+
+Spec::Rake::SpecTask.new(:rcov) do |spec|
+ spec.libs << 'lib' << 'spec'
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov = true
+end
+
+
+task :default => :spec
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ if File.exist?('VERSION.yml')
+ config = YAML.load(File.read('VERSION.yml'))
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
+ else
+ version = ""
+ end
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "foo #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
1 VERSION
@@ -0,0 +1 @@
+0.0.0
12 lib/proxy_stack.rb
@@ -0,0 +1,12 @@
+require 'pancake'
+class ProxyStack < Pancake::Stacks::Short
+ add_root(__FILE__, "proxy_stack")
+
+ # Hook to use before we mount any applications
+ # before_mount_applications do
+ # end
+
+ initialize_stack
+end
+
+require ::File.join(Pancake.get_root(__FILE__, "proxy_stack"), "proxy_stack")
10 lib/proxy_stack/config.ru
@@ -0,0 +1,10 @@
+require 'pancake'
+require ::File.join(::File.expand_path(::File.dirname(__FILE__)), "..", "proxy_stack")
+
+# get the application to run. The applicadtion in the Pancake.start block
+# is the master application. It will have all requests directed to it through the
+# pancake middleware
+# This should be a very minimal file, but should be used when any stand alone code needs to be included
+app = Pancake.start(:root => Pancake.get_root(__FILE__)){ ProxyStack.stackup(:master => true) }
+
+run app
9 lib/proxy_stack/config/config.rb
@@ -0,0 +1,9 @@
+require 'couchrest'
+require 'net/http'
+
+class ProxyStack::Configuration
+ default :proxy_domain, "127.0.0.1", "The default database to conect to"
+ default :proxy_port, 5984, "The default port to proxy to"
+end
+
+
18 lib/proxy_stack/config/environments/development.rb
@@ -0,0 +1,18 @@
+Pancake.logger.info "Loading Development Environment"
+
+# Set the middleware lables to load
+Pancake.stack_labels = [:development]
+
+# Pancake.handle_errors!(true) # uncomment to have the stack handle any errors that occur
+
+class ProxyStack
+ # include middleware for the development stack
+ # stack(:middleware_name).use(MiddlewareClass)
+end
+
+# Add code to hooks. Default available hooks:
+# :before_build_stack, :before_mount_applications, :after_initialize_application, :after_build_stack
+
+# ProxyStack.before_build_stack do
+# # stuff to do
+# end
19 lib/proxy_stack/config/environments/production.rb
@@ -0,0 +1,19 @@
+Pancake.logger.info "Loading Production Environment"
+
+# Set the middleware lables to load
+Pancake.stack_labels = [:production]
+
+Pancake.handle_errors!(true) # uncomment to have the stack handle any errors that occur
+
+class ProxyStack
+ # include middleware for the development stack
+ # stack(:middleware_name).use(MiddlewareClass)
+end
+
+# Add code to hooks. Default available hooks:
+# :before_build_stack, :before_mount_applications, :after_initialize_application, :after_build_stack
+
+# ProxyStack.before_build_stack do
+# # stuff to do
+# end
+
20 lib/proxy_stack/config/environments/staging.rb
@@ -0,0 +1,20 @@
+Pancake.logger.info "Loading Staging Environment"
+
+# Set the middleware lables to load
+Pancake.stack_labels = [:staging]
+
+Pancake.handle_errors!(true) # uncomment to have the stack handle any errors that occur
+
+class ProxyStack
+ # include middleware for the development stack
+ # stack(:middleware_name).use(MiddlewareClass)
+end
+
+# Add code to hooks. Default available hooks:
+# :before_build_stack, :before_mount_applications, :after_initialize_application, :after_build_stack
+
+# ProxyStack.before_build_stack do
+# # stuff to do
+# end
+
+
34 lib/proxy_stack/proxy_stack.rb
@@ -0,0 +1,34 @@
+class ProxyStack
+ helpers do
+ def proxy_request!
+ req = case request.request_method
+ when "GET"
+ Net::HTTP::Get.new(request.path_info)
+ end
+
+ resp = Net::HTTP.start(configuration.proxy_domain, configuration.proxy_port) do |h|
+ h.request(req)
+ end
+ self.status = resp.code.to_i
+ the_headers = []
+ resp.each_header{|h,v| the_headers << [h,v]}
+ self.headers.replace(Hash[the_headers])
+ resp.body
+ end
+
+ def extract_http_headers
+ out = {}
+ request.env.keys.each do |key|
+ if key. =~ /^[A-Z]/
+ out[key] = request.env[key]
+ end
+ end
+ out
+ end
+ end
+
+ any "/({*proxy_path_segements,.*})" do
+ proxy_request!
+ end
+end
+
17 lib/proxy_stack/public/.htaccess
@@ -0,0 +1,17 @@
+# Sets the default handler for FastCGI scripts
+AddHandler fastcgi-script .fcgi
+
+# If Apache2 is used together with mod_fcgid,
+# uncomment the line below and comment in the line
+# above to set the correct script handler
+#AddHandler fcgid-script .fcgi
+
+RewriteEngine On
+
+RewriteRule ^$ index.html [QSA]
+RewriteRule ^([^.]+)$ $1.html [QSA]
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteRule ^(.*)$ merb.fcgi [QSA,L]
+
+
+ErrorDocument 500 "<h2>Application Error</h2>Merb could not be reached"
4 lib/proxy_stack/tasks/proxy_stack.rake
@@ -0,0 +1,4 @@
+namespace :proxy_stack do
+ # Create your tasks here
+end
+
1 pancake_init.rb
@@ -0,0 +1 @@
+require ::File.join(::File.expand_path(::File.dirname(__FILE__)), "lib", "proxy_stack")
11 spec/proxy_stack_spec.rb
@@ -0,0 +1,11 @@
+require ::File.expand_path(::File.dirname(__FILE__) + '/spec_helper')
+
+describe "proxy_stack" do
+ def app
+ proxy_stack.stackup
+ end
+
+ it "fails" do
+ fail "hey buddy, you should probably rename this file and start specing for real"
+ end
+end
13 spec/spec_helper.rb
@@ -0,0 +1,13 @@
+require 'spec'
+require 'rack/test'
+require 'pancake'
+
+
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+require 'proxy_stack'
+
+Spec::Runner.configure do |config|
+ config.include(Rack::Test::Methods)
+ config.include(Pancake::Test::Matchers)
+end

0 comments on commit 8e8d888

Please sign in to comment.