views:

117

answers:

2

In a system that I'm building I want to serve

  1. Static files (static HTML pages and a lot of images), and
  2. Dynamic XML generated by my servlet.

The dynamic XML is generated from my database (through Hibernate) and I use Restlets to serve it in response to API calls. I want to create a static file server (e.g. Apache) so that this does not interfere with the dynamic server traffic. Currently both servers need to run on the same machine.

I've never done something like this before and this is where I'm stuck:

The static HTML pages contain JavaScript that makes API calls to the dynamic server. However, since the two servers operate on different ports, I get stuck with the same origin problem. How can this be solved?

As a bonus, if you can point me to any resources that explain how to create such a static/dynamic content serving system, I'll be happy.

Thanks!

+1  A: 

You need to load a script tag from the Reslet server... have a look at JSONP and this SO post

danswain
+1  A: 

You should setup mod_proxy in apache to forward dynamic requests to whatever backend server you are using. Your existing setup (ie. two separate ports) is perfect, you just need to tell apache 'proxy dynamic requests to my backend server without letting the browser know'.

This page should get you started - http://httpd.apache.org/docs/1.3/mod/mod_proxy.html

sri
Thanks sri. One question: If I do this, do I still implement the JSON approach, or does the same origin policy problem go away in this case?
recipriversexclusion
It goes away. You will configure apache to proxy url patterns like /backend/* to your backend server. Because the browser doesn't know about two servers, same-origin policy problem goes away.
sri
Great, I have installed Apache2 and mod_proxy, now working on this. Thanks for the comments.
recipriversexclusion
YAY, **it works**. Small step for mankind, huge relief for me!
recipriversexclusion