You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-13Lines changed: 24 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -33,28 +33,24 @@ netlify-lambda serve <folder>
33
33
netlify-lambda build <folder>
34
34
```
35
35
36
-
The `serve` function will start a dev server and a file watcher for the specified folder and route requests to the relevant function at:
36
+
At a high level, `netlify-lambda` takes a source folder (e.g. `src/lambda`, specified in your command) and outputs it to a built folder, (e.g. `built-lambda`, specified in your `netlify.toml` file).
37
+
38
+
The `build` function will run a single build of the functions in the folder.
39
+
40
+
The `serve` function will start a dev server for the source folder and route requests with a `.netlify/functions/` prefix, with a default port of `9000`:
37
41
38
42
```
39
-
http://localhost:9000/hello -> folder/hello.js (must export a handler(event, context callback) function)
The `build` function will run a single build of the functions in the folder.
46
+
It also watches your files and restarts the dev server on change. Note: if you add a new file you should kill and restart the process to pick up the new file.
43
47
44
48
**IMPORTANT**:
45
49
46
50
- You need a [`netlify.toml`](https://www.netlify.com/docs/netlify-toml-reference/) file with a `functions` field.
47
51
- Every function needs to be a top-level js/ts/mjs file. You can have subfolders inside the `netlify-lambda` folder, but those are only for supporting files to be imported by your top level function.
48
52
- Function signatures follow the [AWS event handler](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html) syntax but must be named `handler`. [We use Node v8](https://www.netlify.com/blog/2018/04/03/node.js-8.10-now-available-in-netlify-functions/) so `async` functions **are** supported ([beware common mistakes](https://serverless.com/blog/common-node8-mistakes-in-lambda/)!). Read [Netlify Functions docs](https://www.netlify.com/docs/functions/#javascript-lambda-functions) for more info.
49
53
50
-
There are additional CLI options, introduced below:
51
-
```bash
52
-
-h --help
53
-
-c --config
54
-
-p --port
55
-
-s --static
56
-
```
57
-
58
54
## Using with `create-react-app`, Gatsby, and other development servers
59
55
60
56
`react-scripts` (the underlying library for `create-react-app`) and other popular development servers often set up catchall serving for you; in other words, if you try to request a route that doesn't exist, the dev server will try to serve you `/index.html`. This is problematic when you are trying to hit a local API endpoint like `netlify-lambda` sets up for you - your browser will attempt to parse the `index.html` file as JSON. This is why you may see this error:
@@ -93,8 +89,6 @@ module.exports = {
93
89
};
94
90
```
95
91
96
-
The serving port can be changed with the `-p`/`--port` option.
97
-
98
92
<details>
99
93
<summary>
100
94
**Using with `Angular CLI`**
@@ -197,6 +191,21 @@ You may also want to add `typescript @types/node @types/aws-lambda`.
197
191
198
192
Check https://github.com/sw-yx/create-react-app-lambda-typescript for a CRA + Lambda full Typescript experience.
199
193
194
+
## CLI flags/options
195
+
196
+
There are additional CLI options:
197
+
198
+
```bash
199
+
-h --help
200
+
-c --config
201
+
-p --port
202
+
-s --static
203
+
```
204
+
205
+
### --port option
206
+
207
+
The serving port can be changed with the `-p`/`--port` option.
208
+
200
209
### --static option
201
210
202
211
If you need an escape hatch and are building your lambda in some way that is incompatible with our build process, you can skip the build with the `-s` or `--static` flag. [More info here](https://github.com/netlify/netlify-lambda/pull/62).
@@ -225,6 +234,8 @@ You can do a great deal with lambda functions! Here are some examples for inspir
- Raymond Camden's [Adding Serverless Functions to Your Netlify Static Site](https://www.raymondcamden.com/2019/01/08/adding-serverless-functions-to-your-netlify-static-site)
238
+
- Travis Horn's [Netlify Lambda Functions from Scratch](https://travishorn.com/netlify-lambda-functions-from-scratch-1186f61c659e)
228
239
-[**Submit your blogpost here!**](https://github.com/netlify/netlify-lambda/issues/new)
229
240
230
241
These libraries pair very well for extending your functions capability:
0 commit comments