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
+49
Original file line number
Diff line number
Diff line change
@@ -51,6 +51,55 @@ It also watches your files and restarts the dev server on change. Note: if you a
51
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.
52
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.
53
53
54
+
<details>
55
+
<summary>
56
+
<b>Lambda function examples</b>
57
+
</summary>
58
+
If you are new to writing Lambda functions, this section may help you. Function signatures should conform to one of either two styles. Traditional callback style:
console.log(err); // output to netlify function log
91
+
return {
92
+
statusCode:500,
93
+
body:JSON.stringify({ msg:err.message }) // Could be a custom message or object i.e. JSON.stringify(err)
94
+
};
95
+
}
96
+
}
97
+
```
98
+
99
+
`async/await` is nicer :) just return an object
100
+
101
+
</details>
102
+
54
103
## Using with `create-react-app`, Gatsby, and other development servers
55
104
56
105
`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:
0 commit comments