Implement request.path for path parameter mapping
diff --git a/doc/v2/management_interface_v2.md b/doc/v2/management_interface_v2.md
index 8518ac6..e8dc851 100644
--- a/doc/v2/management_interface_v2.md
+++ b/doc/v2/management_interface_v2.md
@@ -308,6 +308,8 @@
}
```
* `target-url`: the backend url
+ * _optional:_ to pass the path of your managed url down to the `target-url`, append `/${request.path}` to the end of `target-url`.
+ Eg. `"target-url": "https://openwhisk.ng.bluemix.net/api/some/action/path.http/${request.path}"`
* `verb`: the method to use when invoking the target-url (use "keep" to use the keep the same verb as the API)
To set a different `target-url` for different paths, use the `operation-switch` policy inside `x-gateway-configuration`.
diff --git a/scripts/lua/policies/backendRouting.lua b/scripts/lua/policies/backendRouting.lua
index bbe21eb..b89f7d9 100644
--- a/scripts/lua/policies/backendRouting.lua
+++ b/scripts/lua/policies/backendRouting.lua
@@ -26,17 +26,23 @@
local _M = {}
--- Set upstream based on the backendUrl
-function _M.setRoute(backendUrl)
+function _M.setRoute(backendUrl, gatewayPath)
local u = url.parse(backendUrl)
if u.scheme == nil then
u = url.parse(utils.concatStrings({'http://', backendUrl}))
end
+ -- pass down gateway path to upstream path if $(request.path) is specified at the end of backendUrl
+ if u.path:sub(-15) == '$(request.path)' then
+ u.path = utils.concatStrings({u.path:sub(1, -16), u.path:sub(-16, -16) == '/' and '' or '/', gatewayPath})
+ ngx.req.set_uri(u.path)
+ else
+ ngx.req.set_uri(getUriPath(u.path))
+ end
ngx.var.backendUrl = backendUrl
- ngx.req.set_uri(getUriPath(u.path))
setUpstream(u)
end
---- Set dynamic route based on the based on the header that is passed in
+--- Set dynamic route based on the header that is passed in
function _M.setDynamicRoute(obj)
local whitelist = obj.whitelist
for k in pairs(whitelist) do
diff --git a/scripts/lua/routing.lua b/scripts/lua/routing.lua
index 4eec452..3fea15b 100644
--- a/scripts/lua/routing.lua
+++ b/scripts/lua/routing.lua
@@ -22,6 +22,7 @@
local url = require "url"
local utils = require "lib/utils"
local request = require "lib/request"
+local logger = require "lib/logger"
-- load policies
local security = require "policies/security"
local mapping = require "policies/mapping"
@@ -85,7 +86,7 @@
setVerb(opFields.backendMethod)
end
-- Set backend upstream and uri
- backendRouting.setRoute(opFields.backendUrl)
+ backendRouting.setRoute(opFields.backendUrl, gatewayPath)
-- Parse policies
if opFields.policies ~= nil then
parsePolicies(dataStore, opFields.policies, key)
diff --git a/tools/travis/build.sh b/tools/travis/build.sh
index 731a74f..114516c 100755
--- a/tools/travis/build.sh
+++ b/tools/travis/build.sh
@@ -50,7 +50,7 @@
# Tests
cd $WHISKDIR
cat whisk.properties
-WSK_TESTS_DEPS_EXCLUDE="-x :core:swift3Action:distDocker -x :core:pythonAction:distDocker -x :core:javaAction:distDocker -x :core:nodejsAction:distDocker -x :core:actionProxy:distDocker -x :sdk:docker:distDocker -x :core:python2Action:copyFiles -x :core:python2Action:distDocker -x :tests:dat:blackbox:badaction:distDocker -x :tests:dat:blackbox:badproxy:distDocker"
+WSK_TESTS_DEPS_EXCLUDE="-x :core:swift3Action:distDocker -x :core:pythonAction:distDocker -x :core:javaAction:distDocker -x :core:nodejsAction:distDocker -x :core:actionProxy:distDocker -x :sdk:docker:distDocker -x :core:python2Action:distDocker -x :tests:dat:blackbox:badaction:distDocker -x :tests:dat:blackbox:badproxy:distDocker"
TERM=dumb ./gradlew tests:test --tests apigw.healthtests.* ${WSK_TESTS_DEPS_EXCLUDE}
sleep 60
TERM=dumb ./gradlew tests:test --tests whisk.core.apigw.* ${WSK_TESTS_DEPS_EXCLUDE}