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

How to reference functions in fittingDef #39

Open
dragos-cojocari opened this issue Jul 18, 2019 · 0 comments
Open

How to reference functions in fittingDef #39

dragos-cojocari opened this issue Jul 18, 2019 · 0 comments

Comments

@dragos-cojocari
Copy link

I cannot figure how to include functions in the configuration for fittings. Using CORS as example I'd like to provide the origin as a function and the only way to do this now is to duplicate the cors fitting in my project's fittings folder like this:

'use strict';

const debug = require('debug')('swagger:cors');
const CORS = require('cors');

// config options: https://www.npmjs.com/package/cors
const options = {
  origin: function() {
    ....
  }
};

module.exports = function create(fittingDef, bagpipes) {
  debug('config: %j', fittingDef);
  const middleware = CORS(Object.assign({}, fittingDef, options));

  return function cors(context, cb) {
    debug('exec');
    middleware(context.request, context.response, cb);
  };
};

What I'd love to be able to just specify the function in Swagger's config.xml :

  bagpipes:
   ...
    cors:
      name: cors
      origin: <Some way to reference the function>

Thank you.

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

1 participant