Skip to content

Commit 4dedb1d

Browse files
author
sw-yx
committed
try to deploy
1 parent 743a354 commit 4dedb1d

26 files changed

+11416
-44
lines changed

.netlify/state.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"siteId": "62390d51-d3e5-4901-a676-8ae1a95ea9dc"
3+
}

example/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

example/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#Netlify Identity + Reach Router by wrapping the goTrue API in a React Hook.
2+
3+
[Deployed site here](https://unruffled-roentgen-04c3b8.netlify.com/)
4+
5+
this is a demo of using Netlify Identity with Reach Router by wrapping the goTrue API in a React Hook.
6+
7+
⚠️Make sure Netlify Identity is enabled!!! or demo wont work
8+
9+
Reach Router is used to show authentication as per [Ryan Florence](https://twitter.com/ryanflorence/status/1060361144701833216).
10+
11+
If you want to fork/deploy this yourself on Netlfiy, click this:
12+
13+
[![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/tree/reachRouterAndGoTrueDemo&stack=cms)

example/lambda/async-dadjoke.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// example of async handler using async-await
2+
// https://github.com/netlify/netlify-lambda/issues/43#issuecomment-444618311
3+
4+
import fetch from "node-fetch"
5+
export async function handler(event, context) {
6+
try {
7+
const response = await fetch("https://icanhazdadjoke.com", { headers: { Accept: "application/json" } })
8+
if (!response.ok) {
9+
// NOT res.status >= 200 && res.status < 300
10+
return { statusCode: response.status, body: response.statusText }
11+
}
12+
const data = await response.json()
13+
14+
return {
15+
statusCode: 200,
16+
body: JSON.stringify({ msg: data.joke })
17+
}
18+
} catch (err) {
19+
console.log(err) // output to netlify function log
20+
return {
21+
statusCode: 500,
22+
body: JSON.stringify({ msg: err.message }) // Could be a custom message or object i.e. JSON.stringify(err)
23+
}
24+
}
25+
}

example/lambda/authEndPoint.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// example of async handler using async-await
2+
// https://github.com/netlify/netlify-lambda/issues/43#issuecomment-444618311
3+
4+
import fetch from 'node-fetch';
5+
export async function handler(event, context) {
6+
if (!context.clientContext && !context.clientContext.identity) {
7+
return {
8+
statusCode: 500,
9+
body: JSON.stringify({
10+
msg:
11+
'No identity instance detected. Did you enable it? Also, Netlify Identity is not supported on local dev yet.'
12+
}) // Could be a custom message or object i.e. JSON.stringify(err)
13+
};
14+
}
15+
const { identity, user } = context.clientContext;
16+
try {
17+
const response = await fetch('https://api.chucknorris.io/jokes/random');
18+
if (!response.ok) {
19+
// NOT res.status >= 200 && res.status < 300
20+
return { statusCode: response.status, body: response.statusText };
21+
}
22+
const data = await response.json();
23+
24+
return {
25+
statusCode: 200,
26+
body: JSON.stringify({ identity, user, msg: data.value })
27+
};
28+
} catch (err) {
29+
console.log(err); // output to netlify function log
30+
return {
31+
statusCode: 500,
32+
body: JSON.stringify({ msg: err.message }) // Could be a custom message or object i.e. JSON.stringify(err)
33+
};
34+
}
35+
}

example/lambda/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "lambda",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "async-dadjoke.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"node-fetch": "^2.4.1"
14+
}
15+
}

example/lambda/yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
node-fetch@^2.4.1:
6+
version "2.4.1"
7+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.4.1.tgz#b2e38f1117b8acbedbe0524f041fb3177188255d"
8+
integrity sha512-P9UbpFK87NyqBZzUuDBDz4f6Yiys8xm8j7ACDbi6usvFm6KItklQUKjeoqTrYS/S1k6I8oaOC2YLLDr/gg26Mw==

example/package.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "example",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@reach/router": "^1.2.1",
7+
"react-netlify-identity": "^0.0.12",
8+
"react-scripts": "3.0.0",
9+
"typescript": "3.4.5"
10+
},
11+
"scripts": {
12+
"start": "react-scripts start",
13+
"build": "react-scripts build",
14+
"test": "react-scripts test",
15+
"eject": "react-scripts eject"
16+
},
17+
"eslintConfig": {
18+
"extends": "react-app"
19+
},
20+
"browserslist": {
21+
"production": [
22+
">0.2%",
23+
"not dead",
24+
"not op_mini all"
25+
],
26+
"development": [
27+
"last 1 chrome version",
28+
"last 1 firefox version",
29+
"last 1 safari version"
30+
]
31+
},
32+
"devDependencies": {
33+
"@types/jest": "24.0.11",
34+
"@types/node": "11.13.8",
35+
"@types/reach__router": "^1.2.4",
36+
"@types/react": "16.8.14",
37+
"@types/react-dom": "16.8.4",
38+
"react": "^16.8.6",
39+
"react-dom": "^16.8.6"
40+
}
41+
}

example/public/_redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* /index.html 200

example/public/favicon.ico

3.78 KB
Binary file not shown.

0 commit comments

Comments
 (0)