Is it possible to use Ambassador prefix_regex and regex_rewrite at the same route mapping?

11/8/2020

I'm trying to use Ambassador prefix_regex and regex_rewrite. <br> I want both this routes prefixes:

       /my/route/<something>
      /api/v1/my/route/<something>

will be mapped to: /my/route/<something> <br> This is what I was trying to use:

apiVersion: ambassador/v2
kind: Mapping
prefix_regex: true
prefix: (/api/v1)?/my/route
regex_rewrite:
    pattern: "/api/v1/my/route/(.*)"
    substitution: "/my/route/\\1"

Using the regex_rewrite with regular prefix works as expected <br> Using prefix_regex with regular rewrite works as expected<br> but together I receive 404 from the envoy.

Any ideas?

I'm using Ambassador 1.7.0 version

-- sapir davidove
ambassador
envoyproxy
kubernetes
mapping
yaml

1 Answer

11/8/2020

Resolved by adding /.* at the end of the prefix. <br>

prefix: (/api/v1)?/my/route/.* <br>

It looks like prefix_regex adds automatically $ at the end of the prefix, which means we need to specify the full path of the mapping and not just the prefix.

-- sapir davidove
Source: StackOverflow