Created
December 30, 2014 06:07
-
-
Save kwgch/51b13ea4718ce24b12fa to your computer and use it in GitHub Desktop.
rackメモ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
$LOAD_PATH.unshift(File.dirname(__FILE__)) | |
require 'hiki/app' | |
require 'rubygems' | |
require 'rack' | |
module Rack | |
class Request | |
def GET | |
if @env["rack.request.query_string"] == query_string | |
@env["rack.request.query_hash"] | |
else | |
p = parse_query(query_string, '&;') | |
@env["rack.request.query_string"] = query_string | |
@env["rack.request.query_hash"] = p | |
end | |
end | |
def POST | |
if @env["rack.input"].nil? | |
raise "Missing rack.input" | |
elsif @env["rack.request.form_input"].equal? @env["rack.input"] | |
@env["rack.request.form_hash"] | |
elsif form_data? || parseable_data? | |
unless @env["rack.request.form_hash"] = parse_multipart(env) | |
form_vars = @env["rack.input"].read | |
# Fix for Safari Ajax postings that always append \0 | |
# form_vars.sub!(/\0\z/, '') # performance replacement: | |
form_vars.slice!(-1) if form_vars[-1] == ?\0 | |
@env["rack.request.form_vars"] = form_vars | |
@env["rack.request.form_hash"] = parse_query(form_vars, '&') | |
@env["rack.input"].rewind | |
end | |
@env["rack.request.form_input"] = @env["rack.input"] | |
@env["rack.request.form_hash"] | |
else | |
{} | |
end | |
end | |
protected | |
def parse_query(qs, d) | |
Utils.parse_nested_query(qs, d) | |
end | |
end | |
end | |
p '********** Rack has been patched! **********' | |
app = Rack::Builder.new{ | |
use Rack::Lint | |
use Rack::ShowExceptions | |
#use Rack::ShowStatus | |
use Rack::CommonLogger | |
use Rack::Static, urls: ['/theme'], root: '.' | |
run Hiki::App.new | |
}.to_app | |
options = { | |
Port: 8080, #実行環境の都合によりポート変えてます | |
Host: '0.0.0.0', | |
AccessLog: [] | |
} | |
Rack::Handler.default.run(app, options) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment