Closed martinmicunda closed 7 years ago
I have follow code:
import koa from 'koa';
import router from 'koa-joi-router';
import validator from './lib/validator';
import * as service from './lib/service';
const app = koa();
const api = router();
const routes = [
{
method: 'GET',
path: '/partners/:id',
validate: validator.findByID,
handler: async() {
const respond = await service.findByID(this.params.id);
this.body = respond.data;
this.status = respond.statusCode;
}
}
];
for(let route of routes) {
api.route(route);
}
app.use(api.middleware());
export default app;
but when I am using async/await
in handler then I am getting follow error:
[ 'AssertionError: route handler must be a GeneratorFunction',
' at isGeneratorFunction (/home/vagrant/api/node_modules/koa-joi-router/joi-router.js:149:3)',
' at Array.forEach (native)',
' at checkHandler (/home/vagrant/api/node_modules/koa-joi-router/joi-router.js:141:23)',
' at Router.validateRouteSpec [as _validateRouteSpec] (/home/vagrant/api/node_modules/koa-joi-router/joi-router.js:127:3)',
' at Router.route (/home/vagrant/api/node_modules/koa-joi-router/joi-router.js:89:8)',
Ah, open a pull request with the fix + a test and we'll get that in for ya. On Oct 6, 2015 9:40 AM, "Martin Micunda" notifications@github.com wrote:
I have follow code:
import koa from 'koa';import router from 'koa-joi-router';import validator from './lib/validator';import * as service from './lib/service'; const app = koa();const api = router(); const routes = [ { method: 'GET', path: '/partners/:id', validate: validator.findByID, handler: async() { const respond = await service.findByID(this.params.id);
this.body = respond.data; this.status = respond.statusCode; } }
]; for(let route of routes) { api.route(route); } app.use(api.middleware()); export default app;
but when I am using async/await in handler then I am getting follow error:
[ 'AssertionError: route handler must be a GeneratorFunction', ' at isGeneratorFunction (/home/vagrant/api/node_modules/koa-joi-router/joi-router.js:149:3)', ' at Array.forEach (native)', ' at checkHandler (/home/vagrant/api/node_modules/koa-joi-router/joi-router.js:141:23)', ' at Router.validateRouteSpec as _validateRouteSpec', ' at Router.route (/home/vagrant/api/node_modules/koa-joi-router/joi-router.js:89:8)',
— Reply to this email directly or view it on GitHub https://github.com/pebble/koa-joi-router/issues/5#issuecomment-145922576 .
How about KOA2?
It seems the module do not support Koa2. Any plans to add it?
I've got a branch going and plan to finish it up before Node 7 is released this month.
5.0.0 is out with async/await support
Should work?? because it's designed for koa, which supports async/await via options/flags but I haven't tried it. On Oct 6, 2015 9:29 AM, "Martin Micunda" notifications@github.com wrote: