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

Just starting out? Need help? Post your questions and find answers here.
User avatar
SparrowhawkMMU
Posts: 291
Joined: Wed Aug 19, 2015 3:02 pm
Location: United Kingdom

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

Post 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 :)
e2robot
Posts: 38
Joined: Wed Mar 19, 2014 8:34 am

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

Post 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
User avatar
SparrowhawkMMU
Posts: 291
Joined: Wed Aug 19, 2015 3:02 pm
Location: United Kingdom

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

Post 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.
User avatar
SparrowhawkMMU
Posts: 291
Joined: Wed Aug 19, 2015 3:02 pm
Location: United Kingdom

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

Post 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
Post Reply