Cross domain using $resource

35 views
Skip to first unread message

Fernando Hernández Elías

unread,
Feb 26, 2015, 6:22:01 PM2/26/15
to ang...@googlegroups.com
I have my angular web app in example.com but all backend stuff is in api.example.com and when I try to do a request to api.example.com/v1/users using $resource I get a chrome CROSS-DOMAIN error. I fixed it with header('Access-Control-Allow-Origin: example.com'); But I think is not the best solution, any ideas?

Sander Elias

unread,
Feb 26, 2015, 11:58:49 PM2/26/15
to ang...@googlegroups.com
Hi Fernando,

Well, yes it is the best solution. You correctly configured CORS on your server! If you server multiple domains from your server, you can let the server put in the 'example.com' part based on the request. (make sure you check it with a list of allowed domains!)

Regards
Sander

Fernando Hernández Elías

unread,
Feb 27, 2015, 12:16:48 PM2/27/15
to ang...@googlegroups.com
Is there a way to "Allow Origin" from multiple sites, because maybe a have:


WEBAPP:

MOBILE WEB APP:

And maybe an iOS app connecting to api.example.com, but PHP only accepts 1 domain in this method: header('Access-Control-Allow-Origin: example.com');

Is there a way to do something like this:

header('Access-Control-Allow-Origin: example.com,webapp.example.com,mobile.example.com');
Reply all
Reply to author
Forward
0 new messages