Skip to content

Commit 9ddd908

Browse files
authored
Merge pull request netlify#1 from verythorough/patch-1
Edit for clarity
2 parents 183f6c3 + c8a1afd commit 9ddd908

File tree

1 file changed

+16
-49
lines changed

1 file changed

+16
-49
lines changed

README.md

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,37 @@
1-
This project is based on [Create React App](https://github.com/facebookincubator/create-react-app).
1+
This project is based on [Create React App](https://github.com/facebookincubator/create-react-app). (For more information about Create react App, check their full [documentation](https://github.com/facebookincubator/create-react-app#create-react-app).)
22

3-
You can follow the docs there to see the full docs on Create React App.
4-
5-
The main addition is a new folder: `src/lambda`. Each js file in there will automatically be deployed and routed as an AWS lambda function by Netlify's continuous deployments.
3+
The main addition is a new folder: `src/lambda`. Each JavaScript file in there will automatically be prepared for Lambda function deployment.
64

75
As an example, we've included a small `src/lambda/hello.js` function, which will be deployed to `/.netlify/functions/hello`.
86

9-
Each function must export a `handler( event, context, callback )` (eaxtly as if the Lambda had been configured with AWS's API Gateway).
7+
## Babel/webpack compilation
108

11-
The event object looks like:
9+
All functions are compiled with webpack using the Babel Loader, so you can use modern JavaScript, import npm modules, etc., without any extra setup.
1210

13-
```js
14-
{
15-
"path": "/.netlify/functions/hello",
16-
"httpMethod": "GET"
17-
"headers": {...}
18-
"queryStringParameters": {...}
19-
"body": "Request Body"
20-
"isBase64Encoded": "A boolean flag to indicate if the applicable request payload is Base64-encode"
21-
}
22-
```
11+
## Local Development
2312

24-
our handler should use the callback to return either an error (as the first parameter) or a response object:
13+
Before developing, clone the repository and run `yarn` from the root of the repo to install all dependencies.
2514

26-
```js
27-
{
28-
"isBase64Encoded": true|false,
29-
"statusCode": httpStatusCode,
30-
"headers": { "headerName": "headerValue", ... },
31-
"body": "..."
32-
}
33-
```
15+
### Run the functions dev server
3416

35-
Here’s a simple example function `hello.js`:
17+
From inside the project folder, run:
3618

37-
```js
38-
exports.handler = function(event, context, callback) {
39-
callback(null, {
40-
statusCode: 200,
41-
body: "Hello, World"
42-
});
43-
}
19+
```
20+
yarn start:lambda
4421
```
4522

46-
## Babel/Webpack compilation
47-
48-
All functions are compiled with webpack using the Babel Loader, so you can use modern JS, import npm modules, etc, without any extra setup.
23+
This will open a local server running at `http://localhost:9000` serving your Lambda functions, updating as you make changes in the `src/lambda` folder.
4924

50-
## Local Development
25+
You can then access your functions directly at `http://localhost:9000/{function_name}`, but to access them with the app, you'll need to start the app dev server.
5126

52-
Before developing, clone the repository and run `yarn` from the root of the repo.
27+
### Run the app dev server
5328

54-
Then open one terminal tab and run:
29+
While the functions server is still running, open a new terminal tab and run:
5530

5631
```
5732
yarn start
5833
```
5934

60-
This will start the normal create-react-app dev server and open your app at `http://localhost:3000`
61-
62-
Then open a separate terminal tab and run:
63-
64-
```
65-
yarn start:lambda
66-
```
67-
68-
This will open a local server running at `http://localhost:9000` serving your lambda functions.
35+
This will start the normal create-react-app dev server and open your app at `http://localhost:3000`.
6936

70-
Requests to `http://localhost:3000/.netlify/functions/*` will automatically be proxied to the lambda dev server.
37+
Local in-app requests to the relative path `/.netlify/functions/*` will automatically be proxied to the local functions dev server.

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