fastify-http-proxy icon indicating copy to clipboard operation
fastify-http-proxy copied to clipboard

Prefix can not handle variables (/path/:var/yy)

Open ifavo opened this issue 2 years ago • 4 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.4.0

Plugin version

8.2.1

Node.js version

16

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.5

Description

When a route with a variable is configured Then the target route is not correctly built

Steps to Reproduce

  fastify.register(proxy, {
    upstream: 'https://upstream',
    prefix: '/path/:var/test',
    rewritePrefix: '/proxied',
    http2: true
  })

Expected Behavior

The rewrite applies the following:

/path/123/test => /proxied

Instead it does:

/path/123/test => /path/123/test

It seems to have only a replace for the route definition (/path/:var/test).

ifavo avatar Aug 15 '22 06:08 ifavo

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

mcollina avatar Aug 15 '22 09:08 mcollina

@mcollina sure, I can try, do you know where fastify has the route-matching implemented?

ifavo avatar Aug 16 '22 04:08 ifavo

It's provided by https://github.com/delvedor/find-my-way

mcollina avatar Aug 16 '22 07:08 mcollina

@mcollina I have added this pull request https://github.com/fastify/fastify-http-proxy/pull/266

I had a little trouble finding my way thru the tests, hopefully it is okay?

ifavo avatar Aug 17 '22 09:08 ifavo