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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support returning body without wrapping it in a function #15

Merged
merged 2 commits into from
Feb 16, 2018

Conversation

kevva
Copy link
Contributor

@kevva kevva commented Feb 16, 2018

Fixes #13 (again 馃槃).

new Promise(resolve => resolve(fn(req, res))).then(val => {
const cb = typeof fn === 'function' ? fn(req, res) : fn;

new Promise(resolve => resolve(cb)).then(val => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to resolve cb in a Promise in case it's a Promise itself.

@coveralls
Copy link

coveralls commented Feb 16, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 439acb8 on kevva:body-without-fn into 03dcb00 on lukechilds:master.

const server = await createTestServer();

server.get('/foo', 'bar');
server.get('/bar', ({ foo: 'bar' }));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of interest, why do you wrap the object in parenthesis here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't return an object otherwise, else it becomes a regular function :).

@lukechilds lukechilds merged commit 5788767 into lukechilds:master Feb 16, 2018
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

Successfully merging this pull request may close these issues.

None yet

3 participants