forked from timlrx/tailwind-nextjs-starter-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
923da1b
commit 2e0aad8
Showing
5 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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_URL = process.env.EMAILOCTOPUS_API_URL | ||
const API_KEY = process.env.EMAILOCTOPUS_API_KEY | ||
const LIST_ID = process.env.EMAILOCTOPUS_LIST_ID | ||
|
||
const data = { email_address: email, api_key: API_KEY } | ||
|
||
const API_ROUTE = `${API_URL}lists/${LIST_ID}/contacts` | ||
|
||
const response = await fetch(API_ROUTE, { | ||
body: JSON.stringify(data), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
method: 'POST', | ||
}) | ||
|
||
if (response.status >= 400) { | ||
return res.status(500).json({ error: `There was an error subscribing to the list.` }) | ||
} | ||
|
||
return res.status(201).json({ error: '' }) | ||
} catch (error) { | ||
return res.status(500).json({ error: error.message || error.toString() }) | ||
} | ||
} |