feat: initial version newsletter

This commit is contained in:
Gautier Arcin
2021-09-02 10:17:34 +02:00
parent ced3cd5f6b
commit c27c6752c9
5 changed files with 16 additions and 19 deletions

View File

@ -2,14 +2,13 @@
export default async (req, res) => {
const { email } = req.body
console.log('hello 1')
if (!email) {
return res.status(400).json({ error: 'Email is required' })
}
try {
const API_KEY = process.env.NEXT_PUBLIC_BUTTONDOWN
// console.log('Api key : ', API_KEY)
const response = await fetch(`https://api.buttondown.email/v1/subscribers`, {
body: JSON.stringify({
email,
@ -20,12 +19,10 @@ export default async (req, res) => {
},
method: 'POST',
})
const badReponse = await response.json()
// console.log('response : ', await response.json())
const responseMessage = await response.json()
if (response.status >= 400) {
return badReponse
return res.status(500).json({ error: responseMessage[0] })
}
return res.status(201).json({ error: '' })