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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

koa-better-body example #116

Closed
Coada opened this issue Feb 19, 2020 · 2 comments
Closed

koa-better-body example #116

Coada opened this issue Feb 19, 2020 · 2 comments

Comments

@Coada
Copy link

Coada commented Feb 19, 2020

Hi,

I ended up finding koa-better-body as it allows setting my own Formidable object, which koa-body does not seem to allow. My project also uses @koa/router.

The koa-better-body example with the router however does not seem to work? I am getting:

var app = require('koa')();
                        ^

TypeError: Class constructor Application cannot be invoked without 'new'
@tunnckoCore
Copy link
Owner

tunnckoCore commented Feb 25, 2020

It's because it most probably shows that example for the Koa prior v2 when Koa became a class.

var Koa = require('koa');
var app = new Koa();

The thing is koa-better-body is working in v1 and v2, and most probably in v3. But until Koa v3 there will be next major release of koa-better-body anyway so not a big problem.

And just to mention. koa-body was just fully re-written by me too.

@tunnckoCore
Copy link
Owner

tunnckoCore commented Feb 25, 2020

@koa/router is fork of the previously most used koa-router.

Both koa v2 and @koa/router export default as class. So the example would become like this

const Koa = require('koa');
const body = require('koa-better-body');
const Router = require('@koa/router');

const app = new Koa();
const router = new Router()

If you are curious for alternatives you can also check koa-better-router if it fit your needs, it's very powerful and flexible.

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

No branches or pull requests

2 participants