Search code examples
node.jsrestcorsaxiosnoip

Why do I get CORS error when I make axios request based on DynDNS url name and not with IP?


I have a Raspberry with Node.js running on it. CORS is installed and configured. I've set up port forwarding but because the IP keeps changing, I registered at a DynDNS provider.

I use React.js with Axios for API requests on localhost:8080.

Interestingly, if I base my requests on (e.g.)

const ROOT_URL = 'http://81.23.563.80:5000/';

which keeps changing every 24h, then the CORS module is doing it's job and I can perform my requests. But if I want do it right and make my request to

const ROOT_URL = 'http://mydyndnsurl.provider.com/';

then I would get he typical error message:

XMLHttpRequest cannot load http://mydyndnsurl.provider.com/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

Does anyone have a solution for this issue?


Solution

  • You still need to include the port number in ROOT_URL:

    const ROOT_URL = 'http://mydyndnsurl.provider.com:5000/';