Secondary Domain website using serverless functions getting a CORS error

I am working on getting a serverless function to work for a secondary domain, but I’m running into a CORS error. The serverless function is working when I hit it with Postman, but when I’m trying to call the endpoint on a website page that is using a secondary domain I’m getting a CORS error, the domain of the webpage that is calling the endpoint is different from the primary domain, which is were the serverless function endpoints are.
How can I add serverless functions to a secondary domain to avoid this since it seems you cannot change CORS settings for serverless functions?

Hi @WAgency7,

Thank you for reaching out to the Community!

From what I can see in our documentation, calling a serverless function from a HubSpot hosted page shouldn’t result in any CORS errors, but calling a serverless function from another domain or with the incorrect protocol (i.e. http instead of https) might (see here for more info).

Are you able to get more information about the CORS error from the serverless function logs (instruction here)?

After you have more information about the error, the MDN’s CORS troubleshooting guide might be useful here.

I also wanted to share this Community article where @piersg and my colleague have shared some helpful information.

I hope this helps!

Cheers
Mia, Community Team

Thank you for the reply! Unforturnetly it seems from the information you provided that there’s no way to handle a request originating from a secondary domain. The primary domain is something like “www.xyz-co.com” and the secondary domain is “www.xyz-other-site.com”, the serverless functions are currently “www.xyz-co.com/_hcms/api/endpoint”.
Is there a way to have serverless functions hosted on a secondary domain? Or is it possible to allow secondary domains as origins?