anypow 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.travis.yml +5 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +10 -0
- data/anypow.gemspec +28 -0
- data/config.ru +4 -0
- data/lib/anypow.rb +8 -0
- data/lib/anypow/app.rb +70 -0
- data/lib/anypow/version.rb +3 -0
- data/spec/anypow/app_spec.rb +16 -0
- data/spec/anypow_spec.rb +6 -0
- data/spec/resources/config.ru +2 -0
- data/spec/spec_helper.rb +2 -0
- metadata +161 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ryosuke IWANAGA
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Anypow
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/riywo/anypow.png?branch=master)](https://travis-ci.org/riywo/anypow)
|
4
|
+
|
5
|
+
Simpe rack proxy to use Pow in any language.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'anypow'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install anypow
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
$ cat config.ru
|
24
|
+
run Anypow::App.new("python -m SimpleHTTPServer $PORT")
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/anypow.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'anypow/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "anypow"
|
8
|
+
spec.version = Anypow::VERSION
|
9
|
+
spec.authors = ["Ryosuke IWANAGA"]
|
10
|
+
spec.email = ["riywo.jp@gmail.com"]
|
11
|
+
spec.description = %q{Pow for any language}
|
12
|
+
spec.summary = %q{Simpe rack proxy to use Pow in any language.}
|
13
|
+
spec.homepage = "https://github.com/riywo/anypow"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rack-proxy"
|
22
|
+
spec.add_dependency "net-empty_port"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "rack-test"
|
28
|
+
end
|
data/config.ru
ADDED
data/lib/anypow.rb
ADDED
data/lib/anypow/app.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require "rack/proxy"
|
2
|
+
require "net/empty_port"
|
3
|
+
|
4
|
+
class Anypow::App < Rack::Proxy
|
5
|
+
def initialize(server_cmd, opts = {})
|
6
|
+
puts "Start anypow server port #{port}, cmd = '#{server_cmd}'"
|
7
|
+
@server_pid = spawn_server(server_env, server_cmd)
|
8
|
+
Net::EmptyPort.wait(port, 3)
|
9
|
+
|
10
|
+
opts[:backend] = server_url
|
11
|
+
|
12
|
+
trap('TERM') { kill_server }
|
13
|
+
trap('INT') { kill_server }
|
14
|
+
trap('QUIT') { kill_server }
|
15
|
+
trap('HUP') { kill_server }
|
16
|
+
trap('KILL') { kill_server }
|
17
|
+
at_exit { kill_server }
|
18
|
+
|
19
|
+
super(opts)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def spawn_server(server_env, server_cmd)
|
25
|
+
if Anypow.ruby_18?
|
26
|
+
require "posix/spawn"
|
27
|
+
cmd = expand_cmd(server_cmd, server_env)
|
28
|
+
POSIX::Spawn.spawn(*spawn_args(server_env, cmd.shellsplit, {}))
|
29
|
+
else
|
30
|
+
Process.spawn(server_env, server_cmd)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def kill_server
|
35
|
+
puts "kill server(pid:#{@server_pid})..."
|
36
|
+
begin
|
37
|
+
Process.kill "SIGKILL", @server_pid
|
38
|
+
Process.waitpid @server_pid
|
39
|
+
rescue Errno::ESRCH
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def port
|
44
|
+
@port ||= Net::EmptyPort.empty_port
|
45
|
+
end
|
46
|
+
|
47
|
+
def server_url
|
48
|
+
"http://127.0.0.1:#{port}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def server_env
|
52
|
+
{ "PORT" => port.to_s }
|
53
|
+
end
|
54
|
+
|
55
|
+
def expand_cmd(server_cmd, server_env)
|
56
|
+
expanded_command = server_cmd.dup
|
57
|
+
server_env.each do |key, val|
|
58
|
+
expanded_command.gsub!("$#{key}", val)
|
59
|
+
end
|
60
|
+
expanded_command
|
61
|
+
end
|
62
|
+
|
63
|
+
def spawn_args(env, argv, options)
|
64
|
+
args = []
|
65
|
+
args << env
|
66
|
+
args += argv
|
67
|
+
args << options
|
68
|
+
args
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "rack/test"
|
2
|
+
|
3
|
+
describe Anypow::App do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
def app
|
7
|
+
config = File.expand_path('../../resources/config.ru', __FILE__)
|
8
|
+
Anypow::App.new("rackup -p $PORT -s webrick #{config}")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "respond from the backend server" do
|
12
|
+
get '/'
|
13
|
+
expect(last_response).to be_ok
|
14
|
+
expect(last_response.body).to eq("Hello Rack!")
|
15
|
+
end
|
16
|
+
end
|
data/spec/anypow_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: anypow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ryosuke IWANAGA
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack-proxy
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: net-empty_port
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rack-test
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Pow for any language
|
111
|
+
email:
|
112
|
+
- riywo.jp@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- .travis.yml
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- anypow.gemspec
|
124
|
+
- config.ru
|
125
|
+
- lib/anypow.rb
|
126
|
+
- lib/anypow/app.rb
|
127
|
+
- lib/anypow/version.rb
|
128
|
+
- spec/anypow/app_spec.rb
|
129
|
+
- spec/anypow_spec.rb
|
130
|
+
- spec/resources/config.ru
|
131
|
+
- spec/spec_helper.rb
|
132
|
+
homepage: https://github.com/riywo/anypow
|
133
|
+
licenses:
|
134
|
+
- MIT
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ! '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 1.8.23
|
154
|
+
signing_key:
|
155
|
+
specification_version: 3
|
156
|
+
summary: Simpe rack proxy to use Pow in any language.
|
157
|
+
test_files:
|
158
|
+
- spec/anypow/app_spec.rb
|
159
|
+
- spec/anypow_spec.rb
|
160
|
+
- spec/resources/config.ru
|
161
|
+
- spec/spec_helper.rb
|