title: How do I enable CORS for custom route in Sails.js
body: <p>I have an Angular 1.x app that calls APIs in my Sails.js app. Whenever I try to call the APIs from my Angular app, I get this - </p>
  
  <p><code>XMLHttpRequest cannot load <a href="http://localhost:1337/portal/login" rel="noreferrer">http://localhost:1337/portal/login</a>. Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains the invalid value ''. Origin '<a href="http://localhost:8080" rel="noreferrer">http://localhost:8080</a>' is therefore not allowed access.</code></p>
  
  <p>Since my Sails.js app has a lot of other APIs which wont be used on this Angular app, I dont wanna apply CORS on all of them by setting <code>allRoutes: true</code> in config/cors.js. So I followed the documentation of Sails.js and have written custom CORS config in this way - </p>
  
  <pre><code>    '/portal/login': {
          target: 'MyController.login',
          cors: {
              origin: '*',
              credentials: true,
              methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH',
              headers: 'content-type, Authorization'
          }
      }
  </code></pre>
  
  <p>But it doesnt work. If I enable <code>allRoutes: true</code> then it starts working but I dont want to enable CORS on all my routes and expose them. I have tried every possible combination of <code>origin, credentials, methods, headers</code> but it always gives the same error.</p>
  
  <p>Can you please help me resolving this? 
  Thankz in advance.</p>