Page 1 of 1

How to call web service running on Apache on same dev Mac?

Posted: Thu Sep 10, 2015 2:56 pm
by SparrowhawkMMU
Hi there,

Hopefully this is a simple question to answer for SpiderBasic experts.

Currently I have an API serving JSON responses on HTTP port 80 (Apache) on my local dev Mac.

If I curl the API locally I get responses. Similarly, if I set up a web page page served locally that makes a GET or POST request to my API, I get the correct data back.

SpiderBasic is serving web pages on port 9080. Calling the same API from SpiderBasic leads to an HTTP error (not sure how to trap the exact one yet in SpiderBasic). Adding :80 to the API URL has no effect.

So the SpiderBasic rendered pages are, I guess, seeing the web service API as a different domain - how do I get around that? It must be a local dev scenario that lots of people have encountered already, so any advice welcome

Thank you :)

Re: How to call web service running on Apache on same dev Ma

Posted: Thu Sep 10, 2015 10:35 pm
by e2robot
Hi,

My previous post might help you setup Apache to allow foreign requests

http://forums.spiderbasic.com/viewtopic ... t=292#p882
However you can make it work from IDE by modifying the following in Apache.

Add in mod_headers.so

and in Directory section add
Header set Access-Control-Allow-Origin "*"

Handy for testing only......
Regards,
Phil

Re: How to call web service running on Apache on same dev Ma

Posted: Fri Sep 11, 2015 7:43 am
by SparrowhawkMMU
Cheers Phil, that's great. I'll try it our later today.

Ah yes, Access-Control-Allow-Origin "*" . Embarassingly I should have known that... one of our front end devs told me about it a while back.

Re: How to call web service running on Apache on same dev Ma

Posted: Fri Sep 11, 2015 1:15 pm
by SparrowhawkMMU
I got it working without doing a global Apache change by sticking the following line in the PHP class that renders the response (dev only, it'll be more specific for live):

Code: Select all

header("Access-Control-Allow-Origin:*");
Thanks again for your help :)


Edit: fixed a typo