Skip to content

Instantly share code, notes, and snippets.

@andrei512
Created November 19, 2013 22:04
Show Gist options
  • Save andrei512/7553385 to your computer and use it in GitHub Desktop.
Save andrei512/7553385 to your computer and use it in GitHub Desktop.
use Rack::Static,
:urls => ["/images", "/js", "/css", "/public"],
:root => "public"
require './webserver.rb'
run KoderWSApp.new
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
</head>
<body>
<form action="/chrome" method="POST">
<input type="text" name="link"/><input type="submit" value="Open"/>
</form>
</body>
</html>
require 'json'
class KoderWSApp
def call env
req = Rack::Request.new(env)
puts JSON.pretty_generate(req.params)
if (env["REQUEST_PATH"] == "/chrome")
`open #{req.params["link"]}`
return [302, {'Content-Type' => 'text','Location' => '/public/index.html'}, ['302 found'] ]
end
[200, {"Content-Type" => "text/html"}, ["Hello World!"]]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment