Module: FuncE::Http
- Defined in:
- lib/func_e/http.rb
Class Method Summary collapse
- .active_pid ⇒ Object
- .has_dependencies? ⇒ Boolean
- .headers ⇒ Object
- .kill_server ⇒ Object
- .node_serve ⇒ Object
- .npm_install ⇒ Object
- .post(func) ⇒ Object
- .start_server ⇒ Object
- .uri ⇒ Object
Class Method Details
.active_pid ⇒ Object
36 37 38 |
# File 'lib/func_e/http.rb', line 36 def self.active_pid `lsof -i:#{Config.config.local_server_port} -t`.to_i end |
.has_dependencies? ⇒ Boolean
40 41 42 |
# File 'lib/func_e/http.rb', line 40 def self.has_dependencies? File.exist?("#{Config.install_path}/package.json") end |
.headers ⇒ Object
9 10 11 |
# File 'lib/func_e/http.rb', line 9 def self.headers { 'Content-Type': 'application/json' } end |
.kill_server ⇒ Object
23 24 25 |
# File 'lib/func_e/http.rb', line 23 def self.kill_server active_pid.tap { |pid| system("kill -9 #{pid}") unless pid.zero? } end |
.node_serve ⇒ Object
32 33 34 |
# File 'lib/func_e/http.rb', line 32 def self.node_serve system("node #{FuncE::SERVER_PATH} --port=#{Config.config.local_server_port} --functions_path=#{Config.install_path}") end |
.npm_install ⇒ Object
27 28 29 30 |
# File 'lib/func_e/http.rb', line 27 def self.npm_install puts "Installing func_e dependencies..." system("cd #{Config.install_path} && npm i && cd #{`pwd`.strip}") end |
.post(func) ⇒ Object
13 14 15 |
# File 'lib/func_e/http.rb', line 13 def self.post(func) Net::HTTP.post(uri, { name: func.name, payload: func.payload }.to_json, headers) end |
.start_server ⇒ Object
17 18 19 20 21 |
# File 'lib/func_e/http.rb', line 17 def self.start_server kill_server npm_install if has_dependencies? Thread.new { node_serve } end |
.uri ⇒ Object
5 6 7 |
# File 'lib/func_e/http.rb', line 5 def self.uri URI("http://localhost:#{FuncE::Config.config.local_server_port}") end |