Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to define proxy.listen_path as exact path? #6198

Open
vm-001 opened this issue Apr 2, 2024 · 4 comments
Open

How to define proxy.listen_path as exact path? #6198

vm-001 opened this issue Apr 2, 2024 · 4 comments

Comments

@vm-001
Copy link

vm-001 commented Apr 2, 2024

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/1 can be proxied to the target_url, which is expected.
  • request to the path /api/v1/users/1/profile now 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.

@vm-001 vm-001 added the bug label Apr 2, 2024
@andyo-tyk
Copy link
Contributor

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.

@vm-001
Copy link
Author

vm-001 commented Apr 2, 2024

@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.

@andyo-tyk
Copy link
Contributor

Hi @vm-001,
Internally, Tyk treats the path as a regex - can you pleae try putting a $ on the end of your listen path?

@vm-001
Copy link
Author

vm-001 commented Apr 4, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants