It works an API from subdomain to domain?

I know that I can only make requests to my API if the request is under the same domain, but I want to know if this also applies to subdomains?

For example, if I have my API at api.domain.com and my website, where I consume that information, is at domain.com, would this work?

Thanks

You basically answered your own question.

You can only make requests to a same (sub)domain, eg., if you have api.domain.ext, you can only make requests to that domain from api.domain.ext, not from domain.ext or www.domain.ext or any other subdomain or domain, for that matter.

A workaround would be to serve your api from /api instead of from a subdomain.

8 Likes

I tried to implement this, but I still having a problem, this is the context: I have something like a “CMS App” where I manage some things for my landing page. Like setting photos or creating articles. This application is hosted in portfoliocms.infinityfreeapp.com and all the information that I configure there is exposed by an API. After I have something like “My landing page” where I consume the API from my “CMS” this is hosted in: axel.portfoliocms.infinityfreeapp.com but the API requests are not working. Both projects are under the same domain or in this case free subdomain. I’m trying this way first because I want to be sure that this works and after buying a domain and using it from here.

These are the errors:

My idea if this works is to have my domain. com for my “landing page” and cms.domain. com for my “CMS App”

Did you read?

5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.