title: Angular4 and Node Server - Response to preflight request doesn't pass access control
body: <p>I have a Angular application in version4. and I have a node server. After posting my form, I am getting the error as I have mentioned in the title.</p>
  
  <p>Failed to load <a href="http://localhost:3100/postEmployee" rel="nofollow noreferrer">http://localhost:3100/postEmployee</a>: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://localhost:3000" rel="nofollow noreferrer">http://localhost:3000</a>' is therefore not allowed access</p>
  
  <p>Code for Node Server is as follows:-</p>
  
  <pre><code>var http=require('http');
  var formidable=require('formidable');
  var util=require('util');
  
  var server=http.createServer(function(req,res){
      res.setHeader('Access-Control-Allow-Origion','*');
      res.setHeader('Access-Control-Allow-Headers',
      'Origion, X-Requested-With,Content-Type,Accept');
  
      if(req.method.toLowerCase( )== 'post')
      {
          processForm(req,res);
      }
      res.end();
  });
  
  function processForm(req,res){
      console.log('Inside processForm');
  var form=new formidable.IncomingForm();
  form.parse(req,function(err,fields){
  
      res.writeHead(200,{
          'content-type':'text\plain'
      });
  
      res.end(unil,inspect({
          fields:fields
      }));
  
      console.log('posted fields\n');
      console.log(util.inspect({
              fields:fields
      }));
  
  })
  
  }
  
  var port=3100;
  server.listen(port);
  console.log("server listening on port " + port);
  </code></pre>
  
  <p>I could see on command prompt the server is running and listening on port 3100.</p>
  
  <p>I tried something mentioned for chrome related to fixing chrome but the same is not working.</p>
  
  <p>Following is the code from the service where form is being post:-</p>
  
  <pre><code>postEmployeeForm(employee : Employee) : Observable&lt;any&gt;{
      let body=JSON.stringify(employee);
      let headers=new Headers({'Content-Type':'application/json'});
  
      let options= new RequestOptions({headers:headers});
  
      return this.http.post("http://localhost:3100/postEmployee"
      ,body,options)
                  .map(this.extractData)
                  .catch(this.handleError);
      //console.log('posting employee : ' + JSON.stringify(employee));
  }
  </code></pre>
  
  <p>any pointers would help.</p>
  
  <p>thanks in advance.</p>
  
  <p>Sidd</p>