1

I've got 2 servers on the same domain but different ports. 80: Apache for html 12345: Some application that delivers JSON or binary data, depending on the request url.

It seems like I can't do simple requests due to the same origin policy. Is there any workaround? Is it maybe possible to forward some types of port 80 urls to port 12345 urls in a way that does not go against the same origin policy?

EDIT: Thanks for the replies but I should probably add that the server that would have to enable CORS is the one on port 12345 which is not apache/nodejs/php. It's a custom application that listens to this port and replies with requested content so there is no simple CORS for me to enable.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Markus
  • 2,174
  • 2
  • 22
  • 37
  • set Apache config to orgin * – ashkufaraz Mar 24 '15 at 20:20
  • You can use headers in your PHP pages: http://stackoverflow.com/a/7564919/1913729 – blex Mar 24 '15 at 20:20
  • I was just doing a similar thing! For my purposes, I just did `if (process.env.NODE_ENV === 'development') { // allow cross domain }` and set the `NODE_ENV` environment flag. On your production server, I'd only allow that domain/port. – m59 Mar 24 '15 at 20:22
  • As a programmer, I'd just write a simple application that sends the request from the server (not webserver) to the custom application using the correct url. You could access that application with php and send it the correct parameters. – Joe Swindell Mar 24 '15 at 20:43
  • @Markus: If you cannot change the port, and cannot set up CORS, you'll have to use a proxy. – Bergi Mar 24 '15 at 20:53
  • 1
    @JoeSwindell The PHP workaround is brilliant, thanks. I'm using PHP now to forward the request to the server at the different port. – Markus Mar 24 '15 at 23:49

0 Answers0