Skip to content

Instantly share code, notes, and snippets.

@OscarGodson
Created May 4, 2014 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OscarGodson/96a4dc690a635816eb34 to your computer and use it in GitHub Desktop.
Save OscarGodson/96a4dc690a635816eb34 to your computer and use it in GitHub Desktop.
app = koa();
app.use(route.post('/sendmail', sendMail));
function *sendMail(email) {
var body = yield parse.form(this);
signup.save(body.email, function (res) {
this.body = res;
});
}
@LeXXik
Copy link

LeXXik commented May 4, 2014

from #koajs

I am still learning myself,so take it with a grain of salt. Your signup.save needs to return a promise. You can change it, or use Q.denodeify. Then it gets easy:

function *sendMail(email) {
  var body = yield parse.form(this);
  var response = yield signup.save(body.email);
  this.body = response;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment