Ambiguous CORS error after following migration guide
Migration guide says: Edit the initial section in your server/middleware.json and add a configuration block for cors middleware:
{
// ...
"initial": {
// ...
"cors": {
"params": {
"origin": true,
"credentials": true,
"maxAge": 86400
}
}
},
// ...
}
Edit the remoting section in your server/config.json and set cors to true:
{
// ...
"remoting": {
// ...
"cors": true,
// ...
}
}
I am getting this error:
Error: The REST adapter no longer comes with a built-in CORS middleware, the config option "remoting.cors" is no longer available.See
Without setting this, I do not get this error. How can I enable CORS then?
Here is the json stack,
"dependencies": {
"apn": "^1.7.5",
"async": "1.0.0",
"bluebird": "^3.0.5",
"body-parser": "^1.14.1",
"chance": "^0.8.0",
"cheerio": "^0.20.0",
"compression": "^1.0.3",
"cookie-parser": "^1.4.0",
"cors": "^2.5.2",
"errorhandler": "^1.1.1",
"express-session": "^1.12.0",
"fs-extra": "^0.26.2",
"helmet": "^1.3.0",
"loopback": "^3.0.0",
"loopback-boot": "^2.6.5",
"loopback-component-explorer": "^2.7.0",
"loopback-component-passport": "^1.6.0",
"loopback-component-storage": "^1.5.1",
"loopback-connector-mongodb": "1.13.0",
"loopback-context": "^1.0.0",
"loopback-datasource-juggler": "^2.47.0",
"loopback-ds-readonly-mixin": "^1.0.0",
"moment": "^2.10.6",
"mongodb": "^2.2.5",
"multer": "^1.0.6",
"needle": "^0.11.0",
"node-gcm": "^0.14.0",
"node-uuid": "^1.4.3",
"passport-facebook": "^2.0.0",
"quickthumb": "0.0.12",
"random-user": "2.0.2",
"serve-favicon": "^2.0.1",
"slug": "^0.9.1",
"strong-error-handler": "^1.1.1",
"underscore": "^1.8.3",
"winston": "^2.1.1",
"winston-loggly": "^1.3.1"
},
+1
Looks like a documentation error. Though the migration guide says to set 'cors' to true, it shows setting it to false. And this page says if 'cors' is false then use the settings in middleware.json: https://loopback.io/doc/en/lb3/config.json.html#overview
Thanks for reporting. Fixed by https://github.com/strongloop/loopback.io/commit/ab6a381d5c781ea117f3f22e6bd5a098835df36b.
There's still a gazillion places in the docs where this isn't corrected yet, how many docs are we maintaining on this? And is cors broken now or...
Great fix, but instead of being unable to enable cors, we are now unable to disable it. Please reopen issue because the error still exists, it's not a documentation only problem.
Hi @buokae thanks for bringing this up. I did find one place that was still incorrect, and I tried to clarify the situation in https://github.com/strongloop/loopback.io/pull/452
If you know of others, please let me know.
NOTE that to disable CORS, you just remove the cors entry in middleware.json. Does that need to be clarified? If you did that, but you still can't disable CORS, please open a new issue, with steps to reproduce. Thanks!
Hi @crandmck , thanks for the answer. In middleware.json.html it says that disabling CORS can be done by setting the cors.params.origin property to false in middleware.json, which is different from what you noted (that to disable CORS, you just remove the cors entry in middleware.json).
I made a pull request on middleware.json.html to clarify CORS a bit more, but perhaps the enabling/disabling of CORS needs a rewrite there too in light of what you said.