title: Deployd - Data retrieved via AngularJS CORS
body: <p>I am currently reading through "Pro AngularJS" by Adam Freeman. In going through the examples, he has the reader create a sports store app using Angular (of course) with a Deployd server resource. The Deployd resource is set up to return JSON data that is to be populated into the model. I am using NodeJS to run my server. It is currently setup on port 5000 (<code>http://localhost:5000/sportsstore/app.html</code>). The Deployd resource is running on port 5500 (<code>http://localhost:5500/products</code>). When hitting Deployd, the response is as follows:</p>
  
  <pre><code>[
      { "name": "Kayak", "description": "A boat for one person", "category": "Watersports", "price": 275, "id": "a1c999fc248b2959" },
      { "name": "Lifejacket", "description": "Protective and fashionable", "category": "Watersports", "price": 48.95, "id": "61303717cfad182e" },
      { "name": "Soccer Ball", "description": "FIFA-approved size and weight", "category": "Soccer", "price": 19.5, "id": "0fb5f67bdcbd992f" },
      { "name": "Corner Flags", "description": "Give your playing field a professional touch", "category": "Soccer", "price": 34.95, "id": "24385d315dd388b4" },
      { "name": "Stadium", "description": "Flat-packed 35,000-seat stadium", "category": "Soccer", "price": 79500, "id": "500fb6805905a856" },
      { "name": "Thinking Cap", "description": "Improve your brain efficiency by 75%", "category": "Chess", "price": 16, "id": "637d8a1f42e6fa1c" },
      { "name": "Unsteady Chair", "description": "Secretly give your opponent a disadvantage", "category": "Chess", "price": 29.95, "id": "73393312ec7dfab7" },
      { "name": "Human Chess Board", "description": "A fun game for the family", "category": "Chess", "price": 75, "id": "7871d02a662b0915" },
      { "name": "Bling-Bling King", "description": "Gold plated, diamon-studded King", "category": "Chess", "price": 1200, "id": "b59a3389a0e248bd" }
  ]
  </code></pre>
  
  <p>I am attempting to retrieve this data through use of <code>$http.get</code>:</p>
  
  <pre><code>$http.get("http://localhost:5500/products")
      .success(function (data) { ... })
      .error(function (error) { ... });
  </code></pre>
  
  <p>However, this keeps returning an error:</p>
  
  <pre><code>XMLHttpRequest cannot load http://localhost:5500/products. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:5000' is therefore not allowed access. 
  </code></pre>
  
  <p>Research shows that there are/were some issues with Angular and CORS, and that the headers had to be configured to run cross-domain requests. As a result, I added the following to my app.config:</p>
  
  <pre><code>$http.defaults.useXDomain = true;
  delete $http.defaults.headers.common['X-Requested-With']; // this isn't needed anymore, but was put here as a just-in-case
  </code></pre>
  
  <p>Despite having these settings added, I am still getting the error. The Deployd documentation says that it is automatically configured for CORS (<a href="http://docs.deployd.com/docs/collections/reference/http.md">Cross-Origin Requests</a>) and will send the appropriate header information as long as the request did not contain invalid custom headers. I'm pretty sure my request does not contain invalid custom headers:</p>
  
  <pre><code>Accept: application/json, text/plain, */*
  Cache-Control: max-age=0
  Origin: http://localhost:5000
  Referer: http://localhost:5000/sportsstore/app.html
  User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36
  </code></pre>
  
  <p><strong>My Question: Is there some other configuration I need to put in place in order to have Deployd configured to allow the CORS request to process? The book does not specify any of the special Angular header settings or anything else.</strong></p>