Netlify Function to obfuscate adding a trailing slash

Ello!
So I have a lovely looking site running on thunderous-cascaron-280d07.netlify.app

I wanted to obfuscate the email address on the contact page so ma using a netlify function:

exports.handler = async function () {
  // hiding email from bots in repo
  const names = { first: 'FIRSTNAME' }
  const provider = 'DOMAIN.COM'
  const constructedEmail = `${Object.values(names)}@${provider}`

  console.log('Constructed Email:', constructedEmail);


  return {
    statusCode: 301,
    headers: {
      'Cache-control': 'public, max-age=0, must-revalidate',
      'location': `mailto:${constructedEmail.replace(/\s/g, '')}`
    },
  }
}

This works and triggers the email program - however it adds a / to the email address e.g. FIRSTNAME@DOMAIN.com/

I added the regex as I thought maybe it was being added as part of the script but seems it is something else - is there a different way to trigger the mailto or am I missing a setting in Netlify to stop it adding the / ?

I tried the Netlify AI help which suggested using a fetch instead of just calling the function:

exports.handler = async () => {
  return {
    statusCode: 200,
    body: "mailto:NAME@WEBSITE.org"
  };
};

if I just return the mailto itself and do a window.location.href = mailtoLink it works but I would love to know why the first method adds the / if anyone knows!

@maxray Have you resolved this?

When I click the link the 301 doesn’t contain a trailing /.

Yeah I have used the 2nd solution which works - I was just interested as to why the first way doesn’t, I can only assume when you do header location it treats it as a url and so adds the/ automagically?

Could you share a link to the deploy where you had the first approach?