Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't know why this question has been downvoted, because this is actually an interesting issue, and one I had myself and worked out a solution to. Specifically, I like building my apps such that the front-end is a static site (<a href="http://roots.cx/" rel="nofollow">roots</a>/<a href="http://backbonejs.org/" rel="nofollow">backbone</a>/<a href="http://marionettejs.com/" rel="nofollow">marionette</a> is a wonderful stack), and pulls data from a separate API app without cross-origin issues, and while keeping cookies intact so that I don't need to do token auth or anything. I'm not sure if you are up against a similar issue here, but it seems like you might be so here's how I solved it.</p> <p>What I did is mapped both my servers onto a single domain name using <a href="http://nginx.org/" rel="nofollow">nginx</a> (I wrote a <a href="http://carrot.is/coding/nginx_introduction" rel="nofollow">getting started guide here</a>). This way, you have no cross-domain issues and they work together quite smoothly. You can use directive like the following to make this happen with nginx:</p> <pre><code>server { listen 1234; server_name localhost; # re-route all api requests and remove the # /api piece before routing them through location /api { rewrite ^(/api)(.*)$ /$2 break; proxy_pass http://localhost:1337; proxy_set_header Host $http_host; } # pass through all other requests to the front end. # in production this should be compiled and use a regular # try_files block location / { proxy_pass http://localhost:8080; proxy_set_header Host $http_host; } } </code></pre> <p>With this code in place, you will have a server set up at <code>localhost:1234</code> that puts through all normal requests to your front-end running at <code>8080</code> and any request starting with <code>/api</code> to your node server at <code>1337</code>. In addition, since both are on the same domain, you won't have any cross-origin issues. This setup works nicely both locally and in production.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload