website icon indicating copy to clipboard operation
website copied to clipboard

Bug report: fix blog updates subscription form

Open michaldziuba03 opened this issue 2 years ago • 2 comments

It's impossible to subscribe blog updates.

screenshot

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).

website/src/api/submit.js

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 });
    });
}

michaldziuba03 avatar Jul 02 '23 21:07 michaldziuba03

Hi, I'd really like to contribute, can I work in this ?

naveen8801 avatar Jul 03 '23 05:07 naveen8801

Hi @naveen8801 Thanks for your interest As this is an environment variable issue. It will be fixed from our end.

jainpawan21 avatar Jul 03 '23 05:07 jainpawan21