I’m working on a site built with Gatsby, running on Netlify, and using functions for some simple 3rd-party API proxy behaviour. I only setup the functions a week or so ago using netlify-lambda & zip it and ship it and ran into a few minor niggles.
As advised, I’m switching over my setup to the awesome netlify dev
. I’ve installed the cli, logged in and linked my repo. So far, it’s genuinely amazing .
Gatsby has express under the hood, meaning it has some really neat built-in proxying features, including the documented advanced proxying for netlify functions:
My netlify-lambda setup required me to run a separate server for functions on port 9000, as shown in the Gatsby documentation.
With netlify dev
, it seems like functions are always served on port 34567? I couldn’t find this documented anywhere, but the CLI outputs:
Waiting for localhost:8000.Lambda server is listening on 34567
Some time later I also get:
◈ Server now ready on http://localhost:8888
I changed by gatsby dev middleware to point at port 34567, and everything seems to work great. This is the same behaviour I had with netlify-lambda, but for me I had trouble getting functions to work with required modules in production.
As far as I understand, as a result of running netlify dev
in my project I now have:
localhost:8000
← gatsby’s dev server
localhost:8888
← netlify’s dev server
localhost:34567
← netlify’s function server
Running netlify dev --help
shows me:
-c, --command=command command to run
-d, --dir=dir dir with static files
-f, --functions=functions Specify a functions folder to serve
-l, --live Start a public live session
-o, --offline disables any features that require network access
-p, --port=port port of netlify dev
So I can customise the main port, and the function directory, but not the function port?
Can someone clarify:
- is the functions port always 34567?
- is this configurable (what if I want to dev multiple projects?)
- which env in my netlify.toml should be used? Is it just the default
[build]
or is there a[context.development]
env? - what does netlify dev do in the background with my functions? Is zip-it-and-ship-it automatically being run? I
Basically, I’m trying to figure out 1) a reliably config for gatsby proxy and 2) following on from my issue with netlify lambda, if this works locally how does it work and why does it then not work in prodcution without the manual zip-it-and-ship-it step
Is there more detailed docs somewhere that I missed? I assume they’re WIP
This isn’t urgent, just testing for fun at the moment!