title: Getting CORS error in angularJS front end
body: <p>I am using a flask server with an angular front end.  Up until recently, I was running the project on my local and had no issues.  </p>
  
  <p>I now moved my project to a remote server and have been getting the following error.  I am not sure what i'm doing wrong:</p>
  
  <p>My error:</p>
  
  <blockquote>
    <p>XMLHttpRequest cannot load <a href="http://ec2-..../api/loginStatus/" rel="nofollow">http://ec2-..../api/loginStatus/</a>. No
    'Access-Control-Allow-Origin' header is present on the requested
    resource. Origin '<a href="http://localhost:8100" rel="nofollow">http://localhost:8100</a>' is therefore not allowed
    access. The response had HTTP status code 503.</p>
  </blockquote>
  
  <p>The snippets of my flask server side code (where I am adding my headers to the response is given below):</p>
  
  <pre><code>@app.after_request
  def after_request(response):
      response.headers.add('Access-Control-Allow-Origin','http://localhost:8100')
      response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
      response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
      response.headers.add('Access-Control-Allow-Credentials', 'true')
      return response
  </code></pre>
  
  <p>I use both restangular and $http methods in my front end angularjs.  </p>
  
  <p>I have added the following lines in the .config of my main module:</p>
  
  <pre><code>.config(['RestangularProvider', '$stateProvider', '$urlRouterProvider','$httpProvider',
    function(RestangularProvider, $stateProvider, $urlRouterProvider,$httpProvider) {
  
          //$httpProvider.defaults.useXDomain = true;
          $httpProvider.defaults.headers.common['Access-Control-Allow-Origin'] = "http://localhost:8100";
          $httpProvider.defaults.withCredentials = true;
          $httpProvider.defaults.headers.common = 'Content-Type: application/json';
          delete $httpProvider.defaults.headers.common['X-Requested-With'];
  </code></pre>
  
  <p>Would someone be able to help me out here?  I've referred to a lot of material and I am not sure what i'm doing wrong.</p>
  
  <p>PS: I am getting 200 status messages on my server.  I am therefore assuming that the error is in my front end and not my server side.  Please correct me if I am wrong</p>
  
  <p>Regards,
  Sunil</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Hi everyone, I have solved the issue.  I would like to thank @Mathijs Segers and @Hassan Mehmood for their inputs.</p>
  
  <p>It turns out that there was a nginx configuration issue which led to the server becoming unavailable.  </p>
  
  <p>Firstly, there was an issue with the symbolic link that was being created for the flask backend (I am running my server side through a git repo on /home/username and then creating a symbolic link at /var/www/sitename.com</p>
  
  <p>I was also throttling the number of requests that can be sent in a second (users could send only 1 every 2 seconds) resulting in the 503 error.</p>
  
  <p>The original code I put up worked fine after I fixed it.</p>