title: main.js:295 DELETE http://127.0.0.1:8081/messages/:0 405 (Method Not Allowed) in Javascript
body: <p>I'm trying to send a restful with JSON Delete request in JavaScript to nodeJS server to delete a message in a chat app. I tried to enable DELETE method through the request headers but it wouldn't work..</p>
  
  <p><strong>How can I enable DELETE method in here?</strong></p>
  
  <p>Here is the client request: </p>
  
  <pre><code>function requestPoll(props) {
              return new Promise(function(resolve, reject) {
                      var xhr = new XMLHttpRequest();
                      xhr.open(props.method, props.action);
                      xhr.timeout = 500; // time in milliseconds
                      if (props.method === 'post') {
                              xhr.setRequestHeader('Content-Type', 'application/json');
                      }
                      xhr.addEventListener('load', function(e) {
                              resolve(e.target.responseText);
                      });
  
                      xhr.send(JSON.stringify(props.data));
  
              });
      }
  </code></pre>
  
  <p>here I send the request:</p>
  
  <pre><code>requestPoll({
  
                                      method: "DELETE",
                                      action: "/messages/:"+i 
  
  }); 
  </code></pre>
  
  <p>and the server code:</p>
  
  <pre><code>var http = require('http');
  var urlUtil = require('url');
  var queryUtil = require('querystring');
  
  var server = http.createServer(function(request, response) {
  
      var strData,name,index;
  
      response.setHeader("Access-Control-Allow-Origin", "*");
      response.setHeader("Access-Control-Allow-Credentials", "true");
      response.setHeader("Access-Control-Allow-Methods", "GET , OPTIONS , POST , DELETE ");
      response.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
      response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
  
      if( request.method === 'DELETE' ){ // delete message
  
          if((url.path).includes("/messages/:")){
  
                  console.log("DELETE");
                  index = parseInt( (url.path).substring( (url.path).indexOf(':')+1, (url.path).length ) ); // get message number
                  (Babble.messages).splice( index ,1);
  
          }
  
      } else {
          response.writeHead(405);
          response.end();
      }
  
  });
  </code></pre>