开发者

How to solve JavaScript origin problem with an application and static file server

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 sam开发者_如何学编程e 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!


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜