cli: Invalid Content-Type for Netlify Dev forms request

Describe the bug

When running Netlify Functions locally via netlify dev and making a POST request to a function endpoint, I’m getting the following console error:

Invalid Content-Type for Netlify Dev forms request

To Reproduce

Steps to reproduce the behavior:

  1. Generate a new netlify function using netlify functions:create hello-world
  2. Pick [hello-world] template
  3. Serve newly created function locally with netlify dev
  4. Make request to local function endpoint (using Postman, curl etc…)
    • Set method to POST
    • Add header: Content-Type: applications/json
  5. Response will contain Invalid Content-Type for Netlify Dev forms request error

Configuration

Using netlify-cli@2.64.1.

netlilfy.toml:

[build]
  functions = "functions"

envinfo:

System:
    OS: macOS 10.15.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 183.36 MB / 32.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.18.2 - ~/.nvm/versions/node/v12.18.2/bin/node
    Yarn: 1.22.5 - ~/.nvm/versions/node/v12.18.2/bin/yarn
    npm: 6.14.5 - ~/.nvm/versions/node/v12.18.2/bin/npm

Expected behavior

No error.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 15
  • Comments: 17 (6 by maintainers)

Most upvoted comments

FWIW I was getting the same error “Invalid Content-Type for Netlify Dev forms request” when my POST url was of the form: http://localhost:<port>/example It works after I corrected that url per @erezrokah http://localhost:<port>/.netlify/functions/example Thanks!

@erezrokah Sure thing. This reproduces it for me. README has the steps & cURL command etc.

Re-opened the issue per https://github.com/netlify/cli/issues/1279#issuecomment-785981336. @hwlmatt please note that the reproduction in that repo is different - you’re not sending the request to the function endpoint. http://localhost:<port>/example should be http://localhost:<port>/.netlify/functions/example

Hi @hwlmatt can you provide a public repo with a reproduction? I’m probably missing something with my setup

@erezrokah Sure thing. This reproduces it for me. README has the steps & cURL command etc.

https://github.com/hwlmatt/netlify-cli-issue.git

This is actually quite shocking. POST is critical to almost any RESTful API and from what I’m seeing I can send a request via GET, PUT, DELETE, etc. and it all works as expected. Using POST however returns the Invalid Content-Type for Netlify Dev forms request message to the node server console.

To this point, my testing has been within the netlify dev sandbox. Will try in a post-deploy environment soon too but for testing purposes it really needs to work in both environments anyway.