# Secondary Domain website using serverless functions getting a CORS error

**URL:** <https://community.hubspot.com/t/secondary-domain-website-using-serverless-functions-getting-a-cors-error/91718>\
**Category:** APIs & Integrations\
**Tags:** cms-content\
**Created:** [October 12, 2023, 4:44pm UTC](https://community.hubspot.com/t/secondary-domain-website-using-serverless-functions-getting-a-cors-error/91718 "2023-10-12T16:44:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![WAgency7](https://avatars.discourse-cdn.com/v4/letter/w/87869e/32.png) [@WAgency7](https://community.hubspot.com/u/WAgency7)\
**Post date:** [October 12, 2023, 4:44pm UTC](https://community.hubspot.com/t/secondary-domain-website-using-serverless-functions-getting-a-cors-error/91718/1 "2023-10-12T16:44:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MiaSrebrnjak](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/miasrebrnjak/32/10_2.png) [@MiaSrebrnjak](https://community.hubspot.com/u/MiaSrebrnjak)\
**Post date:** [October 13, 2023, 10:24am UTC](https://community.hubspot.com/t/secondary-domain-website-using-serverless-functions-getting-a-cors-error/91718/2 "2023-10-13T10:24:23Z")

</div>

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](https://developers.hubspot.com/docs/cms/data/serverless-functions/reference#cors) for more info).

Are you able to get more information about the CORS error from the serverless function logs ([instruction here](https://developers.hubspot.com/docs/cms/data/serverless-functions#viewing-serverless-function-logs))?

After you have more information about the error, the [MDN’s CORS troubleshooting guide](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors) might be useful here.

I also wanted to share [this Community article](https://community.hubspot.com/t5/APIs-Integrations/How-to-create-hubspot-form-using-AJAX-post-call-without-being/m-p/441586) where @piersg and my colleague have shared some helpful information.

I hope this helps!

Cheers  
Mia, Community Team

---

<div class="post-metadata">

**Author:** ![WAgency7](https://avatars.discourse-cdn.com/v4/letter/w/87869e/32.png) [@WAgency7](https://community.hubspot.com/u/WAgency7)\
**Post date:** [October 13, 2023, 9:38pm UTC](https://community.hubspot.com/t/secondary-domain-website-using-serverless-functions-getting-a-cors-error/91718/3 "2023-10-13T21:38:08Z")

</div>

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](http://www.xyz-co.com)” and the secondary domain is “[www.xyz-other-site.com](http://www.xyz-other-site.com)”, the serverless functions are currently “[www.xyz-co.com/](http://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?
