Skip to content

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

@johakoch

Description

@johakoch

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions