Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make plugin compatible with Serverless v0.5 #19

Closed
joostfarla opened this issue Mar 23, 2016 · 8 comments
Closed

Make plugin compatible with Serverless v0.5 #19

joostfarla opened this issue Mar 23, 2016 · 8 comments

Comments

@joostfarla
Copy link
Owner

  • Fix broken functionality
  • Leverage Serverless features, introduced in v0.5
  • Release plugin v0.4.0
@joostfarla joostfarla changed the title make plugin compatible with Serverless v0.5 Make plugin compatible with Serverless v0.5 Mar 23, 2016
@joostfarla
Copy link
Owner Author

Progress can be followed here:

https://github.com/joostfarla/serverless-cors-plugin/tree/v0.4

Big thanks to @ac360! 👍

@joostfarla
Copy link
Owner Author

@ac360 upgrade is almost finished and ready for release. However, I'm having one problem with the new way objects can be populated. The endpointDeployPre hook (addPreflightRequests) does not seem to receive the stage and region. They are both null, so I'm getting warnings on missing template variables. Do you want to take a look at this? Would appreciate!

@minibikini
Copy link

@joostfarla @ac360 @eahefnawy - Hey, guys!

The problem is that the stage and region are not required parameters by EndpointDeploy, it will prompt the user if those are missing.

Ideally we need to somehow run the CORS plugin right after EndpointDeploy._validateAndPrepare().

Since we don't have hooks between pre and post I can see the only way to hook up to _validateAndPrepare() is to use prototypes, instead of S.addHook() mechanism. Something like this:

const _validateAndPrepare = S.classes.EndpointDeploy.prototype._validateAndPrepare;

S.classes.EndpointDeploy.prototype._validateAndPrepare = function() {
  return _validateAndPrepare.call(this).then(() => {
    const cors = new ServerlessCors();
    return cors.addPreflightRequests(this.evt);
  });
};

What do you think?

@joostfarla
Copy link
Owner Author

@minibikini thanks for the input!

You're right in the fact that the problem occurs because the pre hook is fired before the region and stage are being determined or entered. However, this does not hold the plugin from doing its job. In fact, the plugin works perfectly, only some warnings on non-used parameters are being outputted. I'm thinking about just releasing the plugin as-is now and try to find a way to ignore certain parameters or suppress the warnings at a later time.

@joostfarla
Copy link
Owner Author

I've already released the new version, but will keep this issue open until we get rid of the warnings.

@joostfarla
Copy link
Owner Author

One solution could be to let the framework support “partial populations” by passing an array of JSONPath expressions to the toObjectPopulated method. At the moment, the plugin populates the full endpoint configuration and stores it back. However, this full population is in my opinion not a task of this plugin, but of the eventual deployment action in the framework. /cc @ac360

@joostfarla
Copy link
Owner Author

After thinking about this for a while, I think the most simple and logical solution would be:

  • Merge in templates instantly on project loading. I cannot think of a reason why this should be done at a later time. In this specific case, I only need the templates to be populated.
  • Use toObjectPopulated to just populate the environment variables.

This would remove the need to do population from plugins in general. As said before, it's probably unwanted to let plugins populate the environment variables.

@ac360 what do you think?

@joostfarla
Copy link
Owner Author

Just created an issue on the Serverless project (serverless/serverless#1134), which will potentially solve the remaining issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants