Skip to content

Returning promise using cors or other middleware  #49

@kownacki

Description

@kownacki

I have a promise chain in my function and want to enable cors, but to do so I need to wrap my function like that:

module.exports = (req, res) => {
  cors(req, res, () => {
    return thisReturnsPromise()
      .then((errands) => {
        res.status(200).send('OK')
      })
      .catch((error) => {
        res.status(500).send(`Error.`);
      });
  });
};

https://www.npmjs.com/package/cors

The problem is that cors doesn't care if the callback returns promise, so my function cannot wait for my promises and also testing is impossible.

How can I have cors and promises at the same time?

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