javascripthttp-redirectnetlifytomlnetlify-function

Netlify-lambda serve redirects from netlify.toml


I have a working netlify-lambda setup. I run netlify-lambda locally and not in the cloud. Upon running

netlify-lambda serve ./functions

the functions I have defined in the /functions folder are served on localhost:9000

I also have my netlify.toml file in my project root, looking like this:

[build]
  functions = "netlify-lambda"
  publish = "build/"
  command = "npm run build"

[[redirects]]
  from = "/test"
  to = "https://google.com"
  status = 200
  force = true

When I remove the [build] part, then the command "netlify-lambda serve" will result in an error. So I conclude that this file is being used. On the other hand the [[redirects]] instruction does nothing at all.

Requests to

localhost:9000/test

or

localhost:9000/.netlify/functions/test

result in an error like

Function invocation failed: Error: Cannot find module '/home/********/netlify-lambda/test'

What am I missing here?


Solution

  • As described here: https://answers.netlify.com/t/redirects-not-going-to-index-html/20289

    Netlify-lambda will only host your functions and nothing else. You’ll need at least the netlify-cli