title: Restify Delete Method
body: <p>CORS is starting to fry my brain a bit. Everything is good now, apart from one method. I'm building an app with backbone on the frontend and node.js/restify on the backend. The <code>server.coffee</code> looks like this:</p>
  
  <pre><code>server.get '/todos', todos.find_all
  server.get '/todos/:id', todos.find_by_id
  server.del '/todos/:id', todos.delete
  </code></pre>
  
  <p>Whenever a model in backbone calls <code>destroy</code> however I get this rather annoying error:</p>
  
  <p><code>MLHttpRequest cannot load http://localhost:8080/todos/. Method DELETE is not allowed by Access-Control-Allow-Methods.</code></p>
  
  <p>I read about this a bit and using restify done the following:</p>
  
  <pre><code>unknownMethodHandler = (request, response) -&gt;
      if(request.method.toLowerCase() == 'options')
          allowHeaders = ['Accept', 'Accept-Version', 'Content-Type', 'Api-Version']
  
          if(response.methods.indexOf('OPTIONS') == -1) then response.methods.push('OPTIONS')
  
          response.header 'Access-Control-Allow-Credentials', true
          response.header 'Access-Control-Allow-Headers', allowHeaders.join(', ')
          response.header 'Access-Control-Allow-Methods', ['GET', 'DELETE', 'TEST!']
          response.header 'Access-Control-Allow-Origin', request.headers.origin
  
          response.send 204
      else
          response.send new restify.MethodNotAllowedError()
  
  server.on 'MethodNotAllowed', unknownMethodHandler
  </code></pre>
  
  <p>But even still, I get this as the response header:</p>
  
  <pre><code>HTTP/1.1 204 No Content
  Access-Control-Allow-Credentials: true
  Access-Control-Allow-Headers: Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version
  Access-Control-Allow-Methods: GET, OPTIONS
  Access-Control-Allow-Origin: *
  Access-Control-Expose-Headers: X-Api-Version, X-Request-Id, X-Response-Time
  Connection: Keep-Alive
  Date: Mon, 04 Feb 2013 12:24:25 GMT
  Server: restify
  X-Request-Id: fbd4e15a-a22e-48b6-bf5c-a46b94926748
  X-Response-Time: 0
  </code></pre>
  
  <p>I just don't get what I'm doing wrong!</p>