feat: initial version newsletter
This commit is contained in:
@ -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: '' })
|
||||
|
Reference in New Issue
Block a user