padibro padibro - 1 year ago 123
HTTP Question

Server structure for Web application

I have a web application w1 (SPA):
The webserver WS is located in a physical server X
The applicationserver AS il located in an other physical server Y.

The user call the the webserver to start w1 application (http://WS/w1)
Non the browser have the view, but not the data.
To retrieve data w1 applicatio call AS by ajax http GET calls (http://AS/car/df785er/plate for example to retrie a plate of a car)

Summing, in a MVC design, the View is retrieved from WS, the Model is retrieved from AS.

This structure is correct? Or the correct structure is have WS and AS inn the same physical machine?

Answer Source

The structure of your application is correct... BUT the browser by default will block, for security reasons, the ajax requests made to the model AS.

There are several possible solutions. Those I've used are:

  1. enable CORS on AS server. This will allow the browser to make calls to AS It's really easy if you only make GET requests. You simply add an http header (Access-Control-Allow-Origin:) to the response For details on CORS:
  2. Use a reverse proxy on WS to make calls to AS: eg. all requests to /api/ on WS will be reverse proxyed to http://AS/

Which solution to apply depends on security considerations, what type of requests you are making (eg. CORS only allows GET, HEAD amd POST), etc...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download