Skip to content

Commit

Permalink
experimental path based routing
Browse files Browse the repository at this point in the history
  • Loading branch information
mikz committed Sep 13, 2016
1 parent 5dc4061 commit 7382a82
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ local function get_debug_value()
end
end

function _M.find_service(host)
local function find_service_strict(host)
for _,service in ipairs(_M.services or {}) do
for _,_host in ipairs(service.hosts or {}) do
if _host == host then
Expand All @@ -141,6 +141,29 @@ function _M.find_service(host)
end
end

local function find_service_cascade(host)
local request = ngx.var.request
for _,service in ipairs(_M.services or {}) do
for _,_host in ipairs(service.hosts or {}) do
if _host == host then
local usage, matched_patterns = service:extract_usage(request)

if next(usage) and matched_patterns ~= '' then
return service
end
end
end
end

return find_service_strict(host)
end

if os.getenv('APICAST_PATH_ROUTING_ENABLED') then
_M.find_service = find_service_cascade
else
_M.find_service = find_service_strict
end

local http = {
get = function(url)
ngx.log(ngx.INFO, '[http] requesting ' .. url)
Expand Down

0 comments on commit 7382a82

Please sign in to comment.