How to define proxy.listen_path as exact path?
I have an API definition as below:
{
"name": "/api/v1/users/{id}",
"api_id": "1",
"org_id": "test",
"use_keyless": true,
"version_data": {
"not_versioned": true,
"versions": {
"Default": {
"name": "Default",
"use_extended_paths": true
}
}
},
"proxy": {
"listen_path": "/api/v1/users/{id}",
"target_url": "http://host.docker.internal:8000/",
"strip_listen_path": true
},
"active": true
}
- request to the path
/api/v1/users/1can be proxied to the target_url, which is expected. - request to the path
/api/v1/users/1/profilenow be proxied to the target_url as well, which is not expected.
It seems like the proxy.listen_path behaves like a prefix matching, I would like to know why and I'm wondering if there is a way to define a proxy.listen_path as a exact path.
Hi @vm-001,
Have you tried enabling "strict routes" in the Gateway config? This should enable you to get the behaviour you require. https://tyk.io/docs/tyk-oss-gateway/configuration/#http_server_optionsenable_strict_routes
Please let me know if this works for you.
@andyo-tyk Hey. The configuration http_server_options.enable_strict_routes does not work for this case. Request to /api/v1/users/1/profile still be proxied to the target_url.
Hi @vm-001,
Internally, Tyk treats the path as a regex - can you pleae try putting a $ on the end of your listen path?
@andyo-tyk The $ was treated as a literal character.
{
"name": "test",
"api_id": "1",
"org_id": "test",
"use_keyless": true,
"version_data": {
"not_versioned": true,
"versions": {
"Default": {
"name": "Default",
"use_extended_paths": true
}
}
},
"proxy": {
"listen_path": "/api$",
"target_url": "http://host.docker.internal:8888/",
"strip_listen_path": false
},
"active": true
}
$ curl http://localhost:8080/api
Not Found
$ curl http://localhost:8080/api$
proxied to the upstream