add PUBLIC_MANAGEDURL_CONNECT to override HOST:PORT assumption (#269)

* add PUBLIC_MANAGEDURL_CONNECT to override HOST:PORT assumption

Add optional override to assuming that the managed URL can be
constructed simply by concatenating a HOST and PORT pair as HOST:PORT.
This is needed for deployments where multiple services are hosted
using URL rewriting on a single host.

* address review feedback

rename PUBLIC_MANAGEDURL_CONNECT to PUBLIC_GATEWAY_URL and do not
hardwire http protocol for PUBLIC_GATEWAY_URL
diff --git a/api-gateway.conf b/api-gateway.conf
index ecf7b22..f82e06f 100644
--- a/api-gateway.conf
+++ b/api-gateway.conf
@@ -31,6 +31,7 @@
 env REDIS_TIMEOUT;
 env PUBLIC_MANAGEDURL_HOST;
 env PUBLIC_MANAGEDURL_PORT;
+env PUBLIC_GATEWAY_URL;
 env HOST;
 env PORT;
 
diff --git a/scripts/lua/management/lib/apis.lua b/scripts/lua/management/lib/apis.lua
index c27564e..04161f2 100644
--- a/scripts/lua/management/lib/apis.lua
+++ b/scripts/lua/management/lib/apis.lua
@@ -27,6 +27,8 @@
 MANAGEDURL_HOST = (MANAGEDURL_HOST ~= nil and MANAGEDURL_HOST ~= '') and MANAGEDURL_HOST or "0.0.0.0"
 local MANAGEDURL_PORT = os.getenv("PUBLIC_MANAGEDURL_PORT")
 MANAGEDURL_PORT = (MANAGEDURL_PORT ~= nil and MANAGEDURL_PORT ~= '') and MANAGEDURL_PORT or "8080"
+local GATEWAY_URL = os.getenv("PUBLIC_GATEWAY_URL")
+GATEWAY_URL = (GATEWAY_URL ~= nil and GATEWAY_URL ~= '') and GATEWAY_URL or utils.concatStrings({"http://", MANAGEDURL_HOST, ":", MANAGEDURL_PORT})
 
 local _M = {}
 
@@ -87,7 +89,7 @@
   basePath = basePath:sub(-1) == '/' and basePath:sub(1, -2) or basePath
   -- Create managedUrl object
   local uuid = existingAPI ~= nil and existingAPI.id or utils.uuid()
-  local managedUrl = utils.concatStrings({"http://", MANAGEDURL_HOST, ":", MANAGEDURL_PORT, "/api/", decoded.tenantId})
+  local managedUrl = utils.concatStrings({GATEWAY_URL, "/api/", decoded.tenantId})
   if basePath:sub(1,1) ~= '' then
     managedUrl = utils.concatStrings({managedUrl, "/", basePath})
   end