joostfarla / serverless-cors-plugin

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

sls templates break the plugin #9

Closed Alua-Kinzhebayeva closed 8 years ago

Alua-Kinzhebayeva commented 8 years ago

I am running the latest versions of sls and CORS plugin. I have placed my response mappings into s_templates.json, and reference them in s_function as "responses": "$${defaultResponses}". So when I try to use CORS on an endpoint with such mapping, the plugin throws an error serverless:lib.node_modules.serverless.lib.actions.EndpointDeploy TypeError: Cannot assign to read only property 'responseParameters' of $ at /Users/abc/Apps/my_project/node_modules/serverless-cors-plugin/src/index.js:51:39 It is probably due to the fact sls doesn't replace $$ variable with its corespondent value at this stage. And if I replace $$ variable with proper mappings, it works, only OPTIONS method is missing.

lpinca commented 8 years ago

That's correct, the template is not compiled when the hook is fired so endpoint.responses here is the $${whatever} string and thus the error.

No idea how to fix this :/

joostfarla commented 8 years ago

Hmm not sure if this can be fixed without changing the order of how the framework handles the templating. @ac360, any thought on how we can fix this?

openback commented 8 years ago

@joostfarla It looks like you can, as mentioned in https://github.com/serverless/serverless/issues/561

joostfarla commented 8 years ago

@openback thanks for the info! I have a working solution and will probably release it in a few days!

schabert commented 8 years ago

Also waiting for the new release

joostfarla commented 8 years ago

Today it will be released :)

joostfarla commented 8 years ago

Templating support has just been released in v0.3.2. Thanx all!

Please let me know if you experience any problems.