Last active
October 7, 2020 01:53
-
-
Save ronanyeah/c371040936fa0869b4d7bd0e64acb353 to your computer and use it in GitHub Desktop.
Netlify email capture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetch = require("node-fetch"); | |
const email = "[email protected]"; | |
const send = () => | |
fetch("/subscribers", { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json" | |
}, | |
body: JSON.stringify({ email }) | |
}) | |
.then(response => response.json()) | |
.then(console.log) | |
.catch(console.error); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
send : Cmd Msg | |
send = | |
Http.post | |
{ url = "/subscribers" | |
, body = | |
[ ( "email", JE.string "[email protected]" ) ] | |
|> JE.object | |
|> Http.jsonBody | |
, expect = Http.expectWhatever EmailCb | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add BUTTONDOWN_TOKEN to Netlify environment variables | |
# https://docs.netlify.com/configure-builds/file-based-configuration/#inject-environment-variable-values | |
npm run netlify-setup && npm run build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[redirects]] | |
from = "/subscribers" | |
to = "https://api.buttondown.email/v1/subscribers" | |
status = 200 | |
headers = { Authorization = "Token TOKEN_PLACEHOLDER" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"build": "webpack", | |
"netlify-setup": "sed -i s/TOKEN_PLACEHOLDER/${BUTTONDOWN_TOKEN}/g netlify.toml" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment