Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70ef615

Browse files
author
sw-yx
committed
2 parents 9a577c2 + e1e713d commit 70ef615

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ As an example, we've included a small `src/lambda/hello.js` function, which will
66

77
[![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)
88

9+
## Video
10+
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
12+
913
## Babel/webpack compilation
1014

1115
All functions are compiled with webpack using the Babel Loader, so you can use modern JavaScript, import npm modules, etc., without any extra setup.
@@ -50,9 +54,11 @@ This will start the normal create-react-app dev server and open your app at `htt
5054

5155
Local in-app requests to the relative path `/.netlify/functions/*` will automatically be proxied to the local functions dev server.
5256

57+
## Typescript
58+
5359
<details>
5460
<summary>
55-
<b id="typescript">Typescript</b>
61+
<b id="typescript">Click for instructions</b>
5662
</summary>
5763
You can use Typescript in both your React code (with `react-scripts` v2.1+) and your lambda functions )with `netlify-lambda` v1.1+). Follow these instructions:
5864

@@ -61,18 +67,24 @@ You can use Typescript in both your React code (with `react-scripts` v2.1+) and
6167
3. use types in your event handler:
6268

6369
```ts
64-
import { Handler, Context, Callback } from 'aws-lambda';
70+
import { Handler, Context, Callback, APIGatewayEvent } from 'aws-lambda';
6571

6672
interface HelloResponse {
6773
statusCode: number;
6874
body: string;
6975
}
7076

71-
const handler: Handler = (event: any, context: Context, callback: Callback) => {
77+
const handler: Handler = (
78+
event: APIGatewayEvent,
79+
context: Context,
80+
callback: Callback
81+
) => {
82+
const params = event.queryStringParameters;
7283
const response: HelloResponse = {
7384
statusCode: 200,
7485
body: JSON.stringify({
75-
msg: `Hello world ${Math.floor(Math.random() * 10)}`
86+
msg: `Hello world ${Math.floor(Math.random() * 10)}`,
87+
params
7688
})
7789
};
7890

@@ -88,6 +100,8 @@ You are free to set up your `tsconfig.json` and `tslint` as you see fit.
88100

89101
</details>
90102

103+
**If you want to try working in Typescript on the client and lambda side**: There are a bunch of small setup details to get right. Check https://github.com/sw-yx/create-react-app-lambda-typescript for a working starter.
104+
91105
## Service Worker
92106

93107
The service worker does not work with lambda functions out of the box. It prevents calling the function and returns the app itself instead ([Read more](https://github.com/facebook/create-react-app/issues/2237#issuecomment-302693219)). To solve this you have to eject and enhance the service worker configuration in the webpack config. Whitelist the path of your lambda function and you are good to go.

netlify.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[build]
2-
Command = "yarn build"
3-
Functions = "lambda"
4-
Publish = "build"
2+
command = "yarn build"
3+
functions = "lambda"
4+
publish = "build"

0 commit comments

Comments
 (0)