Created
January 12, 2014 14:59
-
-
Save znz/8385630 to your computer and use it in GitHub Desktop.
cross origin example
(see http://qa.atmarkit.co.jp/q/3432 )
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 rackup | |
# -*- coding: utf-8 -*- | |
app = lambda do |env| | |
req = Rack::Request.new(env) | |
res = Rack::Response.new | |
case req.host | |
when /iframe/ | |
res.set_cookie 'key', 'value' | |
if req.cookies["key"] == "value" | |
res.write 'OK' | |
elsif /set/ !~ req.path_info | |
res.redirect("#{req.url}/set") | |
else | |
res.write 'NG' | |
end | |
when /main/ | |
res.write <<-"HTML" | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>cross origin example</title> | |
</head> | |
<body> | |
<h1>cross origin example</h1> | |
<iframe src="http://iframe.127.0.0.1.xip.io:#{req.port}/iframe"></iframe> | |
</body> | |
</html> | |
HTML | |
else | |
res.redirect("#{req.scheme}://main.127.0.0.1.xip.io:#{req.port}/main") | |
end | |
res.finish | |
end | |
run app |
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
source "https://rubygems.org" | |
gem "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
GEM | |
remote: https://rubygems.org/ | |
specs: | |
rack (1.5.2) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
rack |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment