Skip to content

Commit 632e4fd

Browse files
authored
reshuffle the config options
1 parent 175295b commit 632e4fd

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

README.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,24 @@ netlify-lambda serve <folder>
3333
netlify-lambda build <folder>
3434
```
3535

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`:
3741

3842
```
39-
http://localhost:9000/hello -> folder/hello.js (must export a handler(event, context callback) function)
43+
folder/hello.js -> http://localhost:9000/.netlify/functions/hello
4044
```
4145

42-
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.
4347

4448
**IMPORTANT**:
4549

4650
- You need a [`netlify.toml`](https://www.netlify.com/docs/netlify-toml-reference/) file with a `functions` field.
4751
- 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.
4852
- 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.
4953

50-
There are additional CLI options, introduced below:
51-
```bash
52-
-h --help
53-
-c --config
54-
-p --port
55-
-s --static
56-
```
57-
5854
## Using with `create-react-app`, Gatsby, and other development servers
5955

6056
`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 = {
9389
};
9490
```
9591

96-
The serving port can be changed with the `-p`/`--port` option.
97-
9892
<details>
9993
<summary>
10094
**Using with `Angular CLI`**
@@ -197,6 +191,21 @@ You may also want to add `typescript @types/node @types/aws-lambda`.
197191

198192
Check https://github.com/sw-yx/create-react-app-lambda-typescript for a CRA + Lambda full Typescript experience.
199193

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+
200209
### --static option
201210

202211
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
225234
- Slack Notifications: https://css-tricks.com/forms-auth-and-serverless-functions-on-gatsby-and-netlify/#article-header-id-9
226235
- URL Shortener: https://www.netlify.com/blog/2018/03/19/create-your-own-url-shortener-with-netlifys-forms-and-functions/
227236
- Gatsby + Netlify Identity + Functions: [Turning the Static Dynamic: Gatsby + Netlify Functions + Netlify Identity](https://www.gatsbyjs.org/blog/2018-12-17-turning-the-static-dynamic/)
237+
- 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)
228239
- [**Submit your blogpost here!**](https://github.com/netlify/netlify-lambda/issues/new)
229240

230241
These libraries pair very well for extending your functions capability:

0 commit comments

Comments
 (0)