Dynamic Routing for Apicast
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.2 KiB

server {
listen 8082;
location ~ ^/catalog/services/([^/]+)/environments/([^/]+)/target$ {
content_by_lua_block {
local service = ngx.var[1]
local variant = ngx.var[2]
ngx.log(ngx.DEBUG, "Service Catalog request for service = " .. (ngx.var[1] or "<NONE>") .. " and variant = " .. (ngx.var[2] or ""))
local catalog = require "custom/catalog"
if (catalog[service] ~= nil) then
local variants = catalog[service]
if (variants[variant] ~= nil) then
ngx.print(variants[variant])
ngx.exit(ngx.HTTP_OK)
else
-- is there a default environment ?
if (variants._default ~= nil) then
ngx.print(variants._default)
ngx.exit(ngx.HTTP_OK)
else
ngx.status = 404 -- Status needs to be set before the body
ngx.print("") -- Prevent default NGINX Error Page
ngx.exit(ngx.HTTP_NOT_FOUND)
end
end
else
ngx.status = 404 -- Status needs to be set before the body
ngx.print("") -- Prevent default NGINX Error Page
ngx.exit(ngx.HTTP_NOT_FOUND)
end
}
}
}