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

Running netlify dev with the -t flag applies redirection rules to /.netify/functions #1721

Closed
nonAlgebraic opened this issue Jan 11, 2021 · 1 comment
Assignees
Labels
type: bug code to address defects in shipped code

Comments

@nonAlgebraic
Copy link

nonAlgebraic commented Jan 11, 2021

Describe the bug

When running netlify dev with the -t flag to enable some of the recent changes to the redirection engine locally (e.g. automatic passthrough of query parameters), if there is a redirection rule that matches the /.netlify/functions path it causes calls to Netlify functions to fail. This is different from when running netlify dev without the -t flag, where the /.netlify/functions is never redirected even if there are redirection rules that technically match it. Since it's not possible to override this behavior with a redirection rule that matches /.netlify/* paths, there's no way to make functions work together with broadly applying redirection rules.

To Reproduce

  1. Clone this minimal reproduction repo: https://github.com/nonAlgebraic/netlify-cli-functions-redirect-bug-repro
  2. Navigate to the cloned repository
  3. Run yarn install
  4. Run yarn netlify dev -t
  5. See that the Netlify function call invoked by the script on the redirected page is itself redirected, causing the script to fail.
  6. Run yarn netlify dev (without the -t flag)
  7. See that the function call is now successful.

Configuration

netlify.toml:

[dev]
  command = "yarn start"
  framework = "#custom"
  publish = "public"
  targetPort = 8080
  port = 9090

[build]
  functions = "functions"

[[redirects]]
  from = "/*"
  to = "/some-page.html"
  status = 301

Output of envinfo:

System:
  OS: macOS 11.1
  CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Memory: 881.86 MB / 16.00 GB
  Shell: 3.2.57 - /bin/bash
Binaries:
  Node: 14.15.0 - ~/.nvm/versions/node/v14.15.0/bin/node
  Yarn: 1.22.10 - ~/projects/netlify-cli-functions-redirect-bug-repro/node_modules/.bin/yarn
  npm: 6.14.8 - ~/.nvm/versions/node/v14.15.0/bin/npm
  Watchman: 4.9.0 - /usr/local/bin/watchman
npmPackages:
  netlify-cli: ^2.70.0 => 2.70.0 

Expected behavior

When running netlify dev -t, either calls to /.netlify/functions do not have redirection rules applied to them, or it is made possible to override the redirection with a suppresive rule such as

[[redirects]]
  from = "/.netlify/*"
  to = "/.netlify/:splat"
  status = 200

placed before the more general rule.

@erezrokah
Copy link
Contributor

Released in https://github.com/netlify/cli/releases/tag/v3.1.0.
Thanks for the report @nonAlgebraic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

3 participants