Module: FuncE::Http

Defined in:
lib/func_e/http.rb

Class Method Summary collapse

Class Method Details

.active_pidObject



13
14
15
# File 'lib/func_e/http.rb', line 13

def self.active_pid
  `lsof -i:#{Config.config.local_server_port} -t`.to_i
end

.headersObject



9
10
11
# File 'lib/func_e/http.rb', line 9

def self.headers
  { 'Content-Type': 'application/json' }
end

.kill_serverObject



29
30
31
# File 'lib/func_e/http.rb', line 29

def self.kill_server
  active_pid.tap { |pid| system("kill -9 #{pid}") unless pid.zero? }
end

.post(func) ⇒ Object



17
18
19
# File 'lib/func_e/http.rb', line 17

def self.post(func)
  Net::HTTP.post(uri, { name: func.name, payload: func.payload }.to_json, headers)
end

.start_serverObject



21
22
23
24
25
26
27
# File 'lib/func_e/http.rb', line 21

def self.start_server
  kill_server
  
  Thread.new {
    system("node #{FuncE::SERVER_PATH} --port=#{Config.config.local_server_port} --functions_path=#{Config.install_path}")
  }
end

.uriObject



5
6
7
# File 'lib/func_e/http.rb', line 5

def self.uri
  URI("http://localhost:#{FuncE::Config.config.local_server_port}")
end