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 proxy a request while changing path prefix? #772

Open
johakoch opened this issue Oct 5, 2023 · 0 comments
Open

How to proxy a request while changing path prefix? #772

johakoch opened this issue Oct 5, 2023 · 0 comments

Comments

@johakoch
Copy link
Collaborator

johakoch commented Oct 5, 2023

Given a backend providing a route /pfx2/get_something, here mocked with the following config:

server "be" {
  hosts = ["*:8081"]

  api {
    base_path = "/pfx2"

    endpoint "/get_something" {
      response {
        json_body = ["foo", "bar"]
      }
    }
  }
}

Now I want to proxy a request to this backend route while providing the endpoint with a different path prefix: /pfx1/get_something:

server "gw" {
  hosts = ["*:8080"]

  api {
    base_path = "/pfx1"

    endpoint "/get_something" {
      proxy {
        backend = "be"
        url = "/get_something"
      }
    }
  }
}

definitions {
  backend "be" {
    origin = "http://localhost:8081"
    path = "/pfx2/**"
  }
}

Currently, there seems to be no way to do this without either

      proxy {
        backend = "be"
        url = "/get_something"
      }

or

      proxy {
        backend "be" {
          path = "/get_something"
        }
      }

I'd consider both solutions ugly.

Any ideas how to do it more elegantly?

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

No branches or pull requests

1 participant