Two listen path to be used

I want to use two listen path for the time being.
https://api-gateway.test.com/valueOne/

https://api-gateway.test.com/valueTwo/

So, I want both the listen path point to the same place /valueOne/ and /valueTwo/ ? Is there way I can handle that using regex or dsl?

Thank you for the help in advance.

Edit: Modifying my earlier reply. You can use regex. I think the caveat is to ensure it is a go lang regex. There is a similar thread here

You could also use a Url Rewrite at the root. Similar thread also here

Thank you Olu for the quick response. I have a doubt regarding the regex solution you pointed out. Could you please help? the link is It's possible to use regex in the listen path?

Why test: is present in listen path regex? Could you please help here understanding this. Thanks in advance.
"proxy": { "listen_path": "/v{test:[\d]+}/events/", "strip_listen_path": true }

I am asking internally about this and will return with a proper response. In the meantime, I have experimented with it for a some minutes and I think it’s a group catcher of some kind. I am not too sure but your use case can be achieve with:

  • /{?:valueOne|valueTwo}/ or
  • /value{test:[A-Z]{1}[a-z]+}/
1 Like

Thank you. First option worked well. Much appreciated.

/{?:valueOne|valueTwo} :point_left:

Hi Olu…this regex worked but it is flaky. It fails to respond sometimes and give resource not found error once in while when testing through postman. Is that expected? Please let me know

Just confirmed we have a bug where regex listen paths and strip listen paths return inconsistent results. Tyk would still listen on both paths, however, the issue is with sending the data upstream. A workaround would be to use a url-rewrite. Hope this helps.

Ok got it…could you please help me with the url rewrite for the above configuration.

EDIT: I see I may not have understood the context. So I will drop an answer for the two possibilities I think:

  1. If you are using the original solution with url_rewrite, a listen_path at the root and strip_listen_path set to true.
...
"version_data": {
	"not_versioned": true,
	"default_version": "",
	"versions": {
		"Default": {
			"name": "Default",
			"expires": "",
			"paths": {
				"ignored": [],
				"white_list": [],
				"black_list": []
			},
			"extended_paths": {
				"url_rewrites": [
					{
						"path": "/valueTwo",
						"method": "GET",
						"match_pattern": "/valueTwo",
						"rewrite_to": "https://httpbin.org/anything",
						"triggers": []
					},
					{
						"path": "/valueOne",
						"method": "GET",
						"match_pattern": "/valueOne",
						"rewrite_to": "https://httpbin.org/anything",
						"triggers": []
					}
				]
			}
		}
	}
}
  1. If you are using the regex listen_path with strip_listen_path set to false.
...
"extended_paths": {
	"url_rewrites": [
		{
			"path": "/",
			"method": "GET",
			"match_pattern": "/",
			"rewrite_to": "/",
			"triggers": []
		}
	]
}

Depending on your method and path, the one above should work. You may have to orchestrate one yourself for a more complex scenario

Is this solution in Tyk 4.1 consistent or it is still required to use rewrite workaround?

/{?:valueOne|valueTwo}/

I tried and it works for me without workaround.

1 Like

It is consistent with the fix introduced in v4.0.3. So v4.1.0 and v4.2.0 also contain the fix.

1 Like

if i have an API v1/{id}/test can i add regex for this directly in listen_path and target url ?
if so if id can be anything how to add regex for this?

@Olu please help here

my api config

“proxy”: {
“preserve_host_header”: false,
“listen_path”: “/v1/categories/{?:.*}/promotion”,
“target_url”: “http://local-test-url/v1/gateway/categories/{?:.*}/promotion”,
“disable_strip_slash”: false,
“strip_listen_path”: false,
}

"Upstream request URL: /v1/categories/8f9ff163ed8f-yewtfw35728/promotion" 
level=debug msg="Outbound request URL: http://local-test/v1/gateway/categories/%7B/v1/categories/8f9ff163ed8f-yewtfw35728/promotion?:.*}/promotion"

its appending listen path in target url

I don’t recall regex working for target URLs. You can use our URL rewrite for that.

As for the listen_path appended issue, it’s because you have set strip_listen_path to false. You can find more information about proxy settings in our docs.