I was able to use CORS for a specific controller using a GET request like the following:
'get /url': {
controller: 'somecontroller',
action: 'someaction',
cors: true
},
However if I try using POST like the following, I get "Access Denied" error:
'post /url': {
controller: 'somecontroller',
action: 'someaction',
cors: true
},
How do I setup cors for a post method?
With my limited research I found out that simply adding "cors: true" to the controller doesn't solve the problem. Sails is still expecting a
csrf
token for the post method. In thebootstrap.js
file underconfig
folder, I added the following code at the bottom to disablecsrf
token on the route by using the following:If you have better solutions, please post them here. Thanks!
Edit: You can also change this in the
config/csrf.js
file. Changemodule.exports.csrf = true;
to:You might have to use it for your apis