Skip to content

Commit 24aca68

Browse files
committed
Test netlify function for backer email
1 parent 563de27 commit 24aca68

File tree

4 files changed

+32
-75
lines changed

4 files changed

+32
-75
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules/
22
_site/
33
package-lock.json
4+
node-supporters.json
5+
.env

cgi-bin/is-backer.js

-74
This file was deleted.

cgi-bin/user.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const slugify = require("slugify");
2+
3+
exports.handler = async (event, context) => {
4+
const supporters = require("./node-supporters.json");
5+
let isBacker = false;
6+
let name = "";
7+
8+
const {identity, user} = context.clientContext;
9+
let email = user.email;
10+
11+
if(email) {
12+
for(let supporter of supporters.data.collective.members.nodes) {
13+
if(supporter.account.email === email) {
14+
isBacker = true;
15+
name = supporter.account.name;
16+
}
17+
}
18+
}
19+
20+
return {
21+
statusCode: 200,
22+
body: `{
23+
"is-backer": ${isBacker},
24+
"name": "${name}",
25+
"slug": "${slugify(name).toLowerCase()}"
26+
}`
27+
};
28+
};

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"assets": "cp node_modules/@11ty/logo/logo.png .",
88
"build": "eleventy",
9-
"build-production": "node node-avatars.js && ELEVENTY_PRODUCTION=true eleventy"
9+
"build-production": "node node-avatars.js && node node-update-supporters.js && ELEVENTY_PRODUCTION=true eleventy"
1010
},
1111
"repository": {
1212
"type": "git",
@@ -27,6 +27,7 @@
2727
"avatar-local-cache": "^2.0.3",
2828
"chalk": "^2.4.2",
2929
"clean-css": "^4.2.1",
30+
"dotenv": "^8.2.0",
3031
"flat-cache": "^2.0.1",
3132
"fs-extra": "^8.1.0",
3233
"html-minifier": "^3.5.21",

0 commit comments

Comments
 (0)