helapkg / hela

:icecream: Powerful software development experience and management. Enhancing @tc39 JS, @denoland and @nodejs, because we need a bit of magic. :sparkles: You can think of it as Cargo for the JavaScript ecosystem.
Mozilla Public License 2.0
331 stars 41 forks source link

some example with koa@2.x #73

Closed ghost closed 7 years ago

ghost commented 7 years ago

can provide some example usein koa@2.x?

kevinmartin commented 7 years ago

Not tested, but something like this should work:

const app = require('koa')();
const convert = require('koa-convert');
const body = require('koa-better-body');

app.use(convert(body(options));
kevinmartin commented 7 years ago

The README has info on this.

https://github.com/tunnckoCore/koa-better-body#features

tunnckoCore commented 7 years ago

@andy1028 it works (actually v1 middlewares works currently), but with deprecation messages. The correct and current way is to use koa-convert as @KevinMartin shown.

I'm thinking to add example using koa-better-router and instead with koa-router, cuz it is much much flexible and better.

tunnckoCore commented 7 years ago

Actually @KevinMartin example is incorrect.

@andy1028 that is how it looks using koa2

const Koa = require('koa')
const convert = require('koa-convert')
const body = require('koa-better-body')

const app = new Koa()
app.use(convert(body({ some: 'options' })))
app.use(nextV2middleware())

Koa2 requires so much hated calling with new keyword.

maotora commented 7 years ago

@tunnckoCore I would surely like to see examples with koa-better-router cause i'm confussed.

I followed your example on koa-better-router which is using this lib and i got "Not Found" msg whenever i try to reference the route.

tunnckoCore commented 7 years ago

https://github.com/tunnckoCore/koa-better-router/tree/master/recipes - don't think to duplicate them here, I invest a lot time in both better-router and rest-router recipes and their readmes.