cli icon indicating copy to clipboard operation
cli copied to clipboard

Splat not being passed as Query String

Open hrishikesh-k opened this issue 2 years ago • 2 comments

Describe the bug:

Using splat in sending query parameters to a destination doesn't seem to be working.

To reproduce:

Add the following to your netlify.toml:

[[redirects]]
  force = true
  from = "/foo/*"
  status = 301
  to = "/.netlify/functions/bar/?url=:splat"

Create a function with the following:

exports.handler = async ({queryStringParameters}) => {
  return {
    body: JSOSN.strigify(queryStringParameters),
    statusCode: 200
  }
}

The output returns empty.

Configuration

  System:
    OS: macOS 12.2.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 1.44 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.5 - ~/.nvm/versions/node/v14.17.5/bin/node
    npm: 6.14.14 - ~/.nvm/versions/node/v14.17.5/bin/npm
  npmPackages:
    netlify-cli: ^9.4.0 => 9.4.0

Expected behavior

The query string should have some value if the requested URL was /foo/bar/.

CLI Output

N/A

Additional context

N/A

hrishikesh-k avatar Feb 13 '22 14:02 hrishikesh-k

Observations so far: I'm seeing this bug on a local environment with netlify dev on v9.6.4 as well as a local clone of netlify/cli.

It however doesn't seem to be the case in production, testing using code in this repo. For example:

  • Navigating to https://modest-ardinghelli-177f85.netlify.app/foo redirects to https://modest-ardinghelli-177f85.netlify.app/.netlify/functions/bar/?url= with the value {"url":""}.
  • Navigating to https://modest-ardinghelli-177f85.netlify.app/foo /bar redirects to https://modest-ardinghelli-177f85.netlify.app/.netlify/functions/bar/?url=bar with the value {"url":"bar"}.

Currently investigating local env behavior.

jackiewmacharia avatar Mar 17 '22 10:03 jackiewmacharia

@jackiewmacharia It seems like this was done intentionally to match old production behaviour.

See https://github.com/netlify/cli/issues/1605

Relevant code is here: https://github.com/netlify/cli/blob/7b89caf121f77f2343c8057e68d97efbbe5689af/src/utils/proxy.js#L204-L216

tinfoil-knight avatar Jul 26 '22 16:07 tinfoil-knight