Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report: fix blog updates subscription form #96

Open
michaldziuba03 opened this issue Jul 2, 2023 · 2 comments
Open

Bug report: fix blog updates subscription form #96

michaldziuba03 opened this issue Jul 2, 2023 · 2 comments

Comments

@michaldziuba03
Copy link
Contributor

michaldziuba03 commented Jul 2, 2023

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 });
    });
}
@naveen8801
Copy link

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

@jainpawan21
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants