Skip to content

How to reference functions in fittingDef #39

@dragos-cojocari

Description

@dragos-cojocari

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions