Skip to content

Instantly share code, notes, and snippets.

@andrewn
Created October 8, 2013 13:43
Show Gist options
  • Save andrewn/6884876 to your computer and use it in GitHub Desktop.
Save andrewn/6884876 to your computer and use it in GitHub Desktop.
Run PHP scripts via pow.cx
require 'rack'
require 'rack-legacy'
require 'rack-rewrite'
INDEXES = ['index.html','index.php', 'index.cgi']
base_path = Dir.getwd
base_path = "/Users/andrew/Projects/oss/tal/talexample"
use Rack::Rewrite do
base_path = Dir.getwd
base_path = "/Users/andrew/Projects/oss/tal/talexample"
rewrite %r{(.*/$)}, lambda {|match, rack_env|
INDEXES.each do |index|
if File.exists?(File.join(base_path, rack_env['PATH_INFO'], index))
return rack_env['PATH_INFO'] + index
end
end
rack_env['PATH_INFO']
}
end
use Rack::Legacy::Php, base_path
use Rack::Legacy::Cgi, base_path
run Rack::File.new base_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment