Skip to content

Commit f2173f3

Browse files
author
sw-yx
committed
readme
1 parent 06d4d73 commit f2173f3

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
> ⚠️You may not need `netlify-lambda`. [Netlify Dev](https://github.com/netlify/netlify-dev-plugin) works with `create-react-app` out of the box, give it a try! Only use `netlify-lambda` if you need a build step for your functions.
2+
13
This project is based on [Create React App v2](https://github.com/facebookincubator/create-react-app) and [netlify-lambda v1](https://github.com/netlify/netlify-lambda). (For more information about Create react App, check their full [documentation](https://github.com/facebookincubator/create-react-app#create-react-app).)
24

3-
The main addition is a new folder: `src/lambda`. Each JavaScript file in there will automatically be prepared for Lambda function deployment.
5+
The main addition to base Create-React-App is a new folder: `src/lambda`. Each JavaScript file in there will automatically be prepared for Lambda function deployment.
46

57
As an example, we've included a small `src/lambda/hello.js` function, which will be deployed to `/.netlify/functions/hello`. We've also included an async lambda example using async/await syntax in `async-chuck-norris.js`.
68

79
[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/netlify/create-react-app-lambda)
810

911
## Video
1012

11-
Learn how to set this up yourself (and why everything is the way it is) from scratch in a video: https://www.youtube.com/watch?v=3ldSM98nCHI
13+
Learn how to set this up yourself (and why everything is the way it is) from scratch in a video: https://www.youtube.com/watch?v=3ldSM98nCHI
1214

1315
## Babel/webpack compilation
1416

@@ -67,31 +69,27 @@ You can use Typescript in both your React code (with `react-scripts` v2.1+) and
6769
3. use types in your event handler:
6870

6971
```ts
70-
import { Handler, Context, Callback, APIGatewayEvent } from 'aws-lambda';
72+
import { Handler, Context, Callback, APIGatewayEvent } from "aws-lambda"
7173

7274
interface HelloResponse {
73-
statusCode: number;
74-
body: string;
75+
statusCode: number
76+
body: string
7577
}
7678

77-
const handler: Handler = (
78-
event: APIGatewayEvent,
79-
context: Context,
80-
callback: Callback
81-
) => {
82-
const params = event.queryStringParameters;
79+
const handler: Handler = (event: APIGatewayEvent, context: Context, callback: Callback) => {
80+
const params = event.queryStringParameters
8381
const response: HelloResponse = {
8482
statusCode: 200,
8583
body: JSON.stringify({
8684
msg: `Hello world ${Math.floor(Math.random() * 10)}`,
8785
params
8886
})
89-
};
87+
}
9088

91-
callback(undefined, response);
92-
};
89+
callback(undefined, response)
90+
}
9391

94-
export { handler };
92+
export { handler }
9593
```
9694

9795
rerun and see it work!

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy