joostfarla / serverless-cors-plugin

Serverless CORS Plugin - Managing Cross-origin resource sharing (CORS) policies
ISC License
70 stars 15 forks source link

v2.1 exported CORS correctly, v3.1 no longer works #15

Closed brainframe-me closed 8 years ago

brainframe-me commented 8 years ago

Hi,

Is there something significant that changed? I was using serverless v0.4.2 together with serverless-cors-plugin v0.2.1 and then a "serverless endpoint deploy --all" worked perfectly to include the preflight checks etc.. when run in the root of the project. Now when using v0.4.2 with v0.3.1, the same command suddenly crashes with following error:

C:\DATA\serverless-4kgaw\nodejscomponent\resource\show>serverless endpoint deploy --all C:\Users\myusername\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\main\async.js:43 fn = function () { throw arg; }; ^

ServerlessError: Missing required config.component, config.module, config.function, config.endpointMethod, config.endpointPath at new ServerlessError (C:\Users\myusername\AppData\Roaming\npm\node_modules\serverless\lib\ServerlessError.js:17:11) at new ServerlessEndpoint (C:\Users\myusername\AppData\Roaming\npm\node_modules\serverless\lib\ServerlessEndpoint.js:24:122) at C:\DATA\serverless-4kgaw\node_modules\serverless-cors-plugin\src\index.js:98:29 at arrayEach (C:\DATA\serverless-4kgaw\node_modules\serverless-cors-plugin\node_modules\lodash\lodash.js:482:11) at Function.forEach (C:\DATA\serverless-4kgaw\node_modules\serverless-cors-plugin\node_modules\lodash\lodash.js:7720:11) at ServerlessCors.addPreflightRequests (C:\DATA\serverless-4kgaw\node_modules\serverless-cors-plugin\src\index.js:78:9) From previous event: at C:\Users\myusername\AppData\Roaming\npm\node_modules\serverless\lib\Serverless.js:157:29 at Array.reduce (native) at C:\Users\myusername\AppData\Roaming\npm\node_modules\serverless\lib\Serverless.js:156:30 at processImmediate as _immediateCallback From previous event: at Serverless._execute (C:\Users\myusername\AppData\Roaming\npm\node_modules\serverless\lib\Serverless.js:154:10) at Serverless.actions.(anonymous function) (C:\Users\myusername\AppData\Roaming\npm\node_modules\serverless\lib\Serverless.js:382:20) at Serverless.command (C:\Users\myusername\AppData\Roaming\npm\node_modules\serverless\lib\Serverless.js:351:38) at Object. (C:\Users\myusername\AppData\Roaming\npm\node_modules\serverless\bin\serverless:16:12) at Module._compile (module.js:410:26) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Function.Module.runMain (module.js:442:10) at startup (node.js:136:18) at node.js:966:3

I've got following code in s-module.json: { "name": "auth", "profile": "aws-v0.3.1", "custom": { "cors": { "allowOrigin": "*", "allowHeaders": [ "Content-Type", "X-Amz-Date", "Authorization", "X-Api-Key", "x-amz-security-token", "Access-Control-Allow-Origin" ] } }, "cloudFormation": { "resources": {}, "lambdaIamPolicyDocumentStatements": [] } }

Any ideas?

joostfarla commented 8 years ago

In Serverless v0.4 the module concept was dropped, but it has been kept backwards compatible. This change has been reflected in the plugin in v0.3, but without backwards compatibility.

So, probably the best way to solve this is by getting rid of your s-module.json files. Furthermore, the plugin now supports component-level policies. Does this help you?

joostfarla commented 8 years ago

Great, that was the problem. Thanks!