(req, res)
| 1 | import axios from "axios"; |
| 2 | |
| 3 | export default async function handler(req, res) { |
| 4 | try { |
| 5 | const { email } = req.body; |
| 6 | const publicationId = process.env.NEXT_PUBLIC_PUBLICATION_ID; |
| 7 | |
| 8 | // Make the API call to subscribe to the newsletter |
| 9 | const response = await axios.post( |
| 10 | "https://devsintech.hashnode.dev/api/newsletter/subscribe", |
| 11 | { |
| 12 | email, |
| 13 | publicationId, |
| 14 | } |
| 15 | ); |
| 16 | |
| 17 | // Handle the response from the API call |
| 18 | if (response.status === 200) { |
| 19 | res |
| 20 | .status(200) |
| 21 | .json({ message: "Subscribed to the newsletter successfully!" }); |
| 22 | } else { |
| 23 | res.status(500).json({ error: "Error subscribing to the newsletter" }); |
| 24 | } |
| 25 | } catch (error) { |
| 26 | res.status(500).json({ error: "Error subscribing to the newsletter" }); |
| 27 | } |
| 28 | } |
nothing calls this directly
no outgoing calls
no test coverage detected