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

Add support for NestJS 10 #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ await app.init();

[Versioning feature](https://docs.nestjs.com/techniques/versioning#versioning) is not yet supported.

[Search http method](https://github.com/nestjs/nest/pull/10533) is not yet supported by koa-router.

Nest components which operates with Koa response like exception filters needs to use the `koaReply` utility function from
this package because the implementation if the reply in adapter doesn't allow to use standard way of setting
`body` and `status` properties.
Expand Down
85 changes: 43 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nest-koa-adapter",
"version": "3.1.0",
"version": "3.2.0",
"description": "Koa HTTP adapter for Nest.js",
"main": "dist/index.js",
"files": [
Expand Down Expand Up @@ -31,8 +31,8 @@
"koa-router": "12.0.1"
},
"peerDependencies": {
"@nestjs/common": "^9",
"@nestjs/core": "^9"
"@nestjs/common": "^10",
"@nestjs/core": "^10"
},
"optionalDependencies": {
"@koa/cors": "5.0.0",
Expand All @@ -41,9 +41,9 @@
},
"devDependencies": {
"@koa/cors": "5.0.0",
"@nestjs/common": "9.4.3",
"@nestjs/core": "9.4.3",
"@nestjs/testing": "9.4.3",
"@nestjs/common": "10.4.7",
"@nestjs/core": "10.4.7",
"@nestjs/testing": "10.4.7",
"@types/koa": "2.15.0",
"@types/koa-bodyparser": "4.3.12",
"@types/koa-router": "7.4.8",
Expand All @@ -70,4 +70,4 @@
"ts-node": "10.9.2",
"typescript": "4.9.5"
}
}
}
17 changes: 16 additions & 1 deletion src/KoaAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ export class KoaAdapter extends AbstractHttpAdapter<
> {
private router?: KoaRouter;

constructor(instance: Koa = new Koa()) {
constructor(instance: Koa = new Koa(), router?: KoaRouter) {
super(instance);

if (router) {
this.router = router;
}
}

private getRouter(): KoaRouter {
Expand Down Expand Up @@ -301,6 +305,9 @@ export class KoaAdapter extends AbstractHttpAdapter<
[RequestMethod.PATCH]: router.patch,
[RequestMethod.POST]: router.post,
[RequestMethod.PUT]: router.put,
[RequestMethod.SEARCH]: (...args: any[]) => {
throw new Error('SEARCH method not yet supported in koa-router');
},
};

const routeMethod = (
Expand Down Expand Up @@ -334,4 +341,12 @@ export class KoaAdapter extends AbstractHttpAdapter<
public isHeadersSent(response: Koa.Response): any {
return response.headerSent;
}

public appendHeader(response: Koa.Response, name: string, value: string): void {
response.append(name, value);
}

public getHeader(response: Koa.Response, name: string): string {
return response.get(name);
}
}