title: AngularJS : Cross Domain Issue
body: <p>I have a Java web application called <strong>myApp</strong> running on <code>localhost:8080/myApp</code></p>
  
  <p>I created one AngularJS application using Yeoman, Grunt and bower.</p>
  
  <p>In my angularJS application I have one HTML page to register user.</p>
  
  <p>The Controller for the page is</p>
  
  <p><strong>register.js</strong></p>
  
  <pre><code>angular.module('myAppRegister').controller('SignUpController', function($scope,$http) {
      $scope.user = {};
      $scope.registerUser=function()
      {
          $http({
                method: 'POST',
                url: 'http://localhost:8080/myApp/rest/registerUser',
                headers: {'Content-Type': 'application/json'},
                data:  $scope.user
              }).success(function (data) 
                {
                  var strJSON=data;
                  if(strJSON.status=="Success")
                  {
                      $location.path( "/view2" );
                  }
                  else
                  {
                      $scope.status=strJSON.userId+" : "+strJSON.status;
                  }
                });
      }
  });
  </code></pre>
  
  <p>I run it using <strong>grunt server</strong>. When I run the register page, in chrome browser console, it showing error</p>
  
  <pre><code>OPTIONS http://localhost:8080/myApp/rest/registerUser No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
  XMLHttpRequest cannot load http://localhost:8080/myApp/rest/registerUser. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access. 
  </code></pre>
  
  <p>This is my <strong>Gruntfile.js</strong></p>
  
  <pre><code>connect: {
        options: {
          port: 9000,
          // Change this to '0.0.0.0' to access the server from outside.
          hostname: 'localhost'
        },
        proxies: [
          {
              context: '/myApp',
              host: 'localhost',
              port: '8080',
              https: false,
              changeOrigin: false
          }
        ],
        livereload: {
          options: {
            middleware: function (connect) {
              return [
                lrSnippet,
                proxySnippet,
                mountFolder(connect, '.tmp'),
                mountFolder(connect, yeomanConfig.app)    
              ];
            }
          }
        },
        test: {
          options: {
            middleware: function (connect) {
              return [
                mountFolder(connect, '.tmp'),
                mountFolder(connect, 'test')
              ];
            }
          }
        },
  </code></pre>
  
  <p>I searched in Google, and added few lines in the above file.</p>
  
  <pre><code>livereload: {
          options: {
            middleware: function (connect) {
              return [
                lrSnippet,
                proxySnippet,
                mountFolder(connect, '.tmp'),
                mountFolder(connect, yeomanConfig.app),
                function(req, res, next) {
                  res.setHeader('Access-Control-Allow-Origin', '*');
                  res.setHeader('Access-Control-Allow-Methods', '*');
                  next();
                } 
              ];
            }
          }
        },
  </code></pre>
  
  <p>And still I am getting the same errors. 
  What am I doing wrong? And how can I solve this?</p>