Last active
June 30, 2017 17:28
-
-
Save a2ikm/d4c20ec5e186564858ad2ad493ed74e5 to your computer and use it in GitHub Desktop.
This file contains 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
require "json" | |
require "rack/cors" | |
class Page | |
def each | |
loop do | |
count = [1, 2, 3].sample | |
words = %w(one two thee four five six seven).sample(count) | |
json = words.map { |word| | |
{ word: word }.to_json | |
}.join("\n\n") | |
yield json | |
sleep 1 | |
end | |
end | |
end | |
use Rack::Chunked | |
use Rack::Cors do | |
allow do | |
origins '*' | |
resource '*', :headers => :any, :methods => [:get, :post], :expose => ["Transfer-Encoding"] | |
end | |
end | |
app = ->(env) { | |
[ | |
200, | |
{ "Content-Type" => "text/plain" }, | |
Page.new, | |
] | |
} | |
run app |
This file contains 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
# window 1 | |
$ gem install rack-cors | |
$ rackup -s puma | |
# window 2 | |
$ ruby -run -e httpd . -p 8000 | |
# window 3 | |
$ open http://localhost:8000 |
This file contains 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>index</title> | |
<script src="https://raw.githubusercontent.com/eBay/jsonpipe/master/jsonpipe.js"></script> | |
<script> | |
jsonpipe.flow('http://localhost:9292', { | |
"success": function(data) { | |
console.log(data); | |
}, | |
}); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment