evert0n / koa-cors

CORS middleware for Koa
MIT License
243 stars 48 forks source link

Asynchronous origin finding #19

Closed johngeorgewright closed 9 years ago

johngeorgewright commented 9 years ago

At the moment there's no handling for asynchronous operations within the origin finding.

cors({
  origin: function (request) {
    // ... search through database or something just as fun
  }
});

This pull request adds the opportunity to return anything that we can yield (promises etc).

cors({
  origin: function (request) {
    return new Promise(function (resolve) {
      // some asynchronous operation
      resolve(something);
    });
  }
});
evert0n commented 9 years ago

I'm not sure if need to bundle Promises in this module wouldn't be just the case to use another generator with the origin?