mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-13 23:16:47 +00:00
MailChimp
This commit is contained in:
22
pages/api/subscribe.js
Normal file
22
pages/api/subscribe.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import subscribeToMailchimpApi from '@/lib/mailchimp'
|
||||
|
||||
/**
|
||||
* 接受邮件订阅
|
||||
* @param {*} req
|
||||
* @param {*} res
|
||||
*/
|
||||
export default async function handler(req, res) {
|
||||
if (req.method === 'POST') {
|
||||
const { email, firstName, lastName } = req.body
|
||||
try {
|
||||
const response = await subscribeToMailchimpApi({ email, first_name: firstName, last_name: lastName })
|
||||
const data = await response.json()
|
||||
console.log('data', data)
|
||||
res.status(200).json({ status: 'success', message: 'Subscription successful!' })
|
||||
} catch (error) {
|
||||
res.status(400).json({ status: 'error', message: 'Subscription failed!', error })
|
||||
}
|
||||
} else {
|
||||
res.status(405).json({ status: 'error', message: 'Method not allowed' })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user