Skip to content

Commit 9e61bfc

Browse files
attilaoroszNoNameProvided
authored andcommitted
fix: koa deps (#963)
1 parent 1390042 commit 9e61bfc

File tree

6 files changed

+17
-38
lines changed

6 files changed

+17
-38
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ import 'reflect-metadata';
100100

101101
**b. If you want to use routing-controllers with _koa 2_, then install it and all required dependencies:**
102102

103-
`npm install koa koa-router koa-bodyparser koa-multer`
103+
`npm install koa @koa/router koa-bodyparser @koa/multer`
104104

105105
Optionally you can also install their typings:
106106

107-
`npm install -D @types/koa @types/koa-router @types/koa-bodyparser`
107+
`npm install -D @types/koa @types/koa-bodyparser`
108108

109109
4. Install peer dependencies:
110110

@@ -808,7 +808,7 @@ app.listen(3000);
808808
```
809809

810810
To use cors you need to install its module.
811-
For express its `npm i cors`, for koa its `npm i kcors`.
811+
For express its `npm i cors`, for koa its `npm i @koa/cors`.
812812
You can pass cors options as well:
813813

814814
```typescript

docs/lang/chinese/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@
102102

103103
**b. 在 _koa 2_ 中使用 routing-controllers,需要安装以下依赖:**
104104

105-
`npm install koa koa-router koa-bodyparser koa-multer`
105+
`npm install koa @koa/router koa-bodyparser @koa/multer`
106106

107107
可选装它们的类型声明:
108108

109-
`npm install -D @types/koa @types/koa-router @types/koa-bodyparser`
109+
`npm install -D @types/koa @types/koa-bodyparser`
110110

111111
4. 可选依赖
112112

lang/chinese/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@
102102

103103
**b. 在 _koa 2_ 中使用 routing-controllers,需要安装以下依赖:**
104104

105-
`npm install koa koa-router koa-bodyparser koa-multer`
105+
`npm install koa @koa/router koa-bodyparser @koa/multer`
106106

107107
可选装它们的类型声明:
108108

109-
`npm install -D @types/koa @types/koa-router @types/koa-bodyparser`
109+
`npm install -D @types/koa @types/koa-bodyparser`
110110

111111
4. 可选依赖
112112

src/RoutingControllersOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CurrentUserChecker } from './CurrentUserChecker';
99
export interface RoutingControllersOptions {
1010
/**
1111
* Indicates if cors are enabled.
12-
* This requires installation of additional module (cors for express and kcors for koa).
12+
* This requires installation of additional module (cors for express and @koa/cors for koa).
1313
*/
1414
cors?: boolean | Object;
1515

src/driver/BaseDriver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export abstract class BaseDriver {
6868

6969
/**
7070
* Indicates if cors are enabled.
71-
* This requires installation of additional module (cors for express and kcors for koa).
71+
* This requires installation of additional module (cors for express and @koa/cors for koa).
7272
*/
7373
cors?: boolean | Object;
7474

src/driver/koa/KoaDriver.ts

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class KoaDriver extends BaseDriver {
4646
this.koa.use(bodyParser());
4747
if (this.cors) {
4848
// eslint-disable-next-line @typescript-eslint/no-var-requires
49-
const cors = require('kcors');
49+
const cors = require('@koa/cors');
5050
if (this.cors === true) {
5151
this.koa.use(cors());
5252
} else {
@@ -121,9 +121,6 @@ export class KoaDriver extends BaseDriver {
121121
.forEach(param => {
122122
defaultMiddlewares.push(multer(param.extraOptions).array(param.name));
123123
});
124-
125-
// eslint-disable-next-line @typescript-eslint/unbound-method
126-
defaultMiddlewares.push(this.fixMulterRequestAssignment);
127124
}
128125

129126
// user used middlewares
@@ -353,7 +350,7 @@ export class KoaDriver extends BaseDriver {
353350
}
354351

355352
/**
356-
* Dynamically loads koa and required koa-router module.
353+
* Dynamically loads koa module.
357354
*/
358355
protected loadKoa() {
359356
if (require) {
@@ -370,16 +367,16 @@ export class KoaDriver extends BaseDriver {
370367
}
371368

372369
/**
373-
* Dynamically loads koa-router module.
370+
* Dynamically loads @koa/router module.
374371
*/
375372
private loadRouter() {
376373
if (require) {
377374
if (!this.router) {
378375
try {
379-
this.router = new (require('koa-router'))();
376+
this.router = new (require('@koa/router'))();
380377
} catch (e) {
381378
throw new Error(
382-
'koa-router package was not found installed. Try to install it: npm install koa-router@next --save'
379+
'@koa/router package was not found installed. Try to install it: npm install @koa/router --save'
383380
);
384381
}
385382
}
@@ -389,31 +386,13 @@ export class KoaDriver extends BaseDriver {
389386
}
390387

391388
/**
392-
* Dynamically loads koa-multer module.
389+
* Dynamically loads @koa/multer module.
393390
*/
394391
private loadMulter() {
395392
try {
396-
return require('koa-multer');
393+
return require('@koa/multer');
397394
} catch (e) {
398-
throw new Error('koa-multer package was not found installed. Try to install it: npm install koa-multer --save');
399-
}
400-
}
401-
402-
/**
403-
* This middleware fixes a bug on koa-multer implementation.
404-
*
405-
* This bug should be fixed by koa-multer PR #15: https://github.com/koa-modules/multer/pull/15
406-
*/
407-
private async fixMulterRequestAssignment(ctx: any, next: Function) {
408-
if ('request' in ctx) {
409-
if (ctx.req.body) ctx.request.body = ctx.req.body;
410-
if (ctx.req.file) ctx.request.file = ctx.req.file;
411-
if (ctx.req.files) {
412-
ctx.request.files = ctx.req.files;
413-
ctx.files = ctx.req.files;
414-
}
395+
throw new Error('@koa/multer package was not found installed. Try to install it: npm install @koa/multer --save');
415396
}
416-
417-
return await next();
418397
}
419398
}

0 commit comments

Comments
 (0)