website
website copied to clipboard
Bug report: fix blog updates subscription form
It's impossible to subscribe blog updates.
I suspect process.env.MAILCHIMP_URL is undefined, because according to api error, axios tries to hit 127.0.0.1:80 - this is default axios behavior when url is not defined.
Another thing - add .catch() block to give more user friendly error message, because API response shouldn't look like this (look at screenshot).
const axios = require(`axios`);
const validateEmail = (email) =>
String(email)
.toLowerCase()
.match(
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
);
export default function handler(req, res) {
res.setHeader('Access-Control-Allow-Origin', '*');
if (!req?.body?.email || !validateEmail(req?.body?.email)) {
res.status(400).json({ error: true });
return;
}
axios
.post(
process.env.MAILCHIMP_URL, // <--- I think MAILCHIMP_URL is undefined
{
email_address: req.body.email,
status: 'subscribed',
},
{
auth: {
username: 'novu',
password: process.env.MAILCHIMP_URL_KEY,
},
}
)
.then(() => {
res.status(200).json({ sent: true });
});
}
Hi, I'd really like to contribute, can I work in this ?
Hi @naveen8801 Thanks for your interest As this is an environment variable issue. It will be fixed from our end.