wip
This commit is contained in:
parent
95697e2491
commit
ced3cd5f6b
@ -6,4 +6,5 @@ NEXT_PUBLIC_UTTERANCES_REPO=
|
||||
NEXT_PUBLIC_DISQUS_SHORTNAME=
|
||||
NEXT_PUBLIC_MAILCHIMP_API_KEY=
|
||||
NEXT_PUBLIC_MAILCHIMP_API_SERVER=
|
||||
NEXT_PUBLIC_MAILCHIMP_AUDIENCE_ID=
|
||||
NEXT_PUBLIC_MAILCHIMP_AUDIENCE_ID=
|
||||
NEXT_PUBLIC_BUTTONDOWN=
|
@ -19,9 +19,11 @@ const FormSuscribe = () => {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
// console.log('resultat : ', res)
|
||||
const { error } = await res.json()
|
||||
|
||||
// console.log('error :', error)
|
||||
if (error) {
|
||||
console.log('error 2 : ', error)
|
||||
setMessage('You are already subscribed!')
|
||||
return
|
||||
}
|
||||
|
@ -23,12 +23,13 @@ const siteMetadata = {
|
||||
googleAnalyticsId: '', // e.g. UA-000000-2 or G-XXXXXXX
|
||||
},
|
||||
newsletter: {
|
||||
provider: 'mailchimp', // supported providers: mailchimp
|
||||
provider: 'buttondown', // supported providers: mailchimp
|
||||
mailChimpConfig: {
|
||||
apiKey: process.env.NEXT_PUBLIC_MAILCHIMP_API_KEY,
|
||||
apiServer: process.env.NEXT_PUBLIC_MAILCHIMP_API_SERVER,
|
||||
audienceId: process.env.NEXT_PUBLIC_MAILCHIMP_AUDIENCE_ID,
|
||||
},
|
||||
buttonDown: process.env.NEXT_PUBLIC_BUTTONDOWN,
|
||||
},
|
||||
comment: {
|
||||
// Select a provider and use the environment variables associated to it
|
||||
|
35
pages/api/buttondown.js
Normal file
35
pages/api/buttondown.js
Normal file
@ -0,0 +1,35 @@
|
||||
// eslint-disable-next-line import/no-anonymous-default-export
|
||||
export default async (req, res) => {
|
||||
const { email } = req.body
|
||||
|
||||
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,
|
||||
}),
|
||||
headers: {
|
||||
Authorization: `Token ${API_KEY}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
const badReponse = await response.json()
|
||||
// console.log('response : ', await response.json())
|
||||
|
||||
if (response.status >= 400) {
|
||||
return badReponse
|
||||
}
|
||||
|
||||
return res.status(201).json({ error: '' })
|
||||
} catch (error) {
|
||||
return res.status(500).json({ error: error.message || error.toString() })
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
import mailchimp from '@mailchimp/mailchimp_marketing'
|
||||
|
||||
mailchimp.setConfig({
|
||||
apiKey: process.env.NEXT_PUBLIC_MAILCHIMP_API_KEY,
|
||||
server: process.env.NEXT_PUBLIC_MAILCHIMP_API_SERVER, // E.g. us1
|
||||
})
|
||||
|
||||
export default async (req, res) => {
|
||||
const { email } = req.body
|
||||
|
||||
if (!email) {
|
||||
return res.status(400).json({ error: 'Email is required' })
|
||||
}
|
||||
|
||||
try {
|
||||
const test = await mailchimp.lists.addListMember(
|
||||
process.env.NEXT_PUBLIC_MAILCHIMP_AUDIENCE_ID,
|
||||
{
|
||||
email_address: email,
|
||||
status: 'subscribed',
|
||||
}
|
||||
)
|
||||
return res.status(201).json({ error: '' })
|
||||
} catch (error) {
|
||||
return res.status(500).json({ error: error.message || error.toString() })
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ mailchimp.setConfig({
|
||||
server: process.env.NEXT_PUBLIC_MAILCHIMP_API_SERVER, // E.g. us1
|
||||
})
|
||||
|
||||
// eslint-disable-next-line import/no-anonymous-default-export
|
||||
export default async (req, res) => {
|
||||
const { email } = req.body
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user