lib/nephos-server/routing/execute.rb in nephos-server-0.1.8 vs lib/nephos-server/routing/execute.rb in nephos-server-0.1.10
- old
+ new
@@ -18,27 +18,31 @@
# @param path [Array]
# find the right route to use from the url
def self.parse_path path, verb
route = File.join(["/"] + path)
- return ALL.find{|e| e[:url] == route and e[:verb] == verb}
+ return ALL.find{|e| e[:match] =~ route and e[:verb] == verb}
end
def self.execute(env)
- route = URI.parse(env['REQUEST_URI']) rescue (puts "uri err"; return render(status: 500))
+ begin
+ route = URI.parse(env['REQUEST_URI'])
+ rescue => err
+ puts "uri err #{err.message}".red
+ return render(status: 500)
+ end
verb = env["REQUEST_METHOD"]
from = env["REMOTE_ADDR"]
path = route.path.split("/").select{|e|not e.to_s.empty?}
args = Hash[route.query.to_s.split("&").map{|e| e.split("=")}]
puts "#{from} [#{verb}] \t ---> \t #{route}"
parsed = {route: route, verb: verb, from: from, path: path, args: args}
call = parse_path(path, verb)
return render status: 404 if call.nil?
begin
- controller = Module.const_get(call[:controller]).new(env, parsed)
+ controller = Module.const_get(call[:controller]).new(env, parsed, call)
return render(controller.send(call[:method]) || {status: 500})
rescue => err
- # require 'pry'; binding.pry
return render(status: 500)
end
end
end