@kiyasov/platform-hono 1.5.7 → 1.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +5 -2
- package/dist/cjs/src/adapters/hono-adapter.js +11 -11
- package/dist/cjs/src/adapters/hono-adapter.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/adapters/hono-adapter.js +11 -11
- package/dist/esm/src/adapters/hono-adapter.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/adapters/hono-adapter.ts +24 -29
- package/bun.lock +0 -1629
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
NestApplicationOptions,
|
|
12
12
|
RequestHandler,
|
|
13
13
|
} from '@nestjs/common/interfaces';
|
|
14
|
+
import { isObject } from '@nestjs/common/utils/shared.utils';
|
|
14
15
|
import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter';
|
|
15
16
|
import { Context, Next, Hono } from 'hono';
|
|
16
17
|
import { bodyLimit } from 'hono/body-limit';
|
|
@@ -24,9 +25,17 @@ import * as https from 'https';
|
|
|
24
25
|
import { HonoRequest, TypeBodyParser } from '../interfaces';
|
|
25
26
|
|
|
26
27
|
type HonoHandler = RequestHandler<HonoRequest, Context>;
|
|
27
|
-
|
|
28
28
|
type ServerType = http.Server | http2.Http2Server | http2.Http2SecureServer;
|
|
29
29
|
type Ctx = Context | (() => Promise<Context>);
|
|
30
|
+
type Method =
|
|
31
|
+
| 'all'
|
|
32
|
+
| 'get'
|
|
33
|
+
| 'post'
|
|
34
|
+
| 'put'
|
|
35
|
+
| 'delete'
|
|
36
|
+
| 'use'
|
|
37
|
+
| 'patch'
|
|
38
|
+
| 'options';
|
|
30
39
|
|
|
31
40
|
/**
|
|
32
41
|
* Adapter for using Hono with NestJS.
|
|
@@ -80,22 +89,28 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
80
89
|
private async getBody(ctx: Ctx, body?: Data) {
|
|
81
90
|
ctx = await this.normalizeContext(ctx);
|
|
82
91
|
|
|
92
|
+
if (body === undefined && ctx.res && ctx.res.body !== null) {
|
|
93
|
+
return ctx.res;
|
|
94
|
+
}
|
|
95
|
+
|
|
83
96
|
let responseContentType = await this.getHeader(ctx, 'Content-Type');
|
|
84
97
|
|
|
85
98
|
if (!responseContentType || responseContentType.startsWith('text/plain')) {
|
|
86
|
-
if (
|
|
99
|
+
if (
|
|
100
|
+
body instanceof Buffer ||
|
|
101
|
+
body instanceof Uint8Array ||
|
|
102
|
+
body instanceof ArrayBuffer ||
|
|
103
|
+
body instanceof ReadableStream
|
|
104
|
+
) {
|
|
87
105
|
responseContentType = 'application/octet-stream';
|
|
88
|
-
} else if (
|
|
106
|
+
} else if (isObject(body)) {
|
|
89
107
|
responseContentType = 'application/json';
|
|
90
108
|
}
|
|
91
109
|
|
|
92
|
-
this.setHeader(ctx, 'Content-Type', responseContentType);
|
|
110
|
+
await this.setHeader(ctx, 'Content-Type', responseContentType);
|
|
93
111
|
}
|
|
94
112
|
|
|
95
|
-
if (
|
|
96
|
-
responseContentType === 'application/json' &&
|
|
97
|
-
typeof body === 'object'
|
|
98
|
-
) {
|
|
113
|
+
if (responseContentType === 'application/json' && isObject(body)) {
|
|
99
114
|
return ctx.json(body);
|
|
100
115
|
} else if (body === undefined) {
|
|
101
116
|
return ctx.newResponse(null);
|
|
@@ -105,15 +120,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
private registerRoute(
|
|
108
|
-
method:
|
|
109
|
-
| 'all'
|
|
110
|
-
| 'get'
|
|
111
|
-
| 'post'
|
|
112
|
-
| 'put'
|
|
113
|
-
| 'delete'
|
|
114
|
-
| 'use'
|
|
115
|
-
| 'patch'
|
|
116
|
-
| 'options',
|
|
123
|
+
method: Method,
|
|
117
124
|
pathOrHandler: string | HonoHandler,
|
|
118
125
|
handler?: HonoHandler,
|
|
119
126
|
) {
|
|
@@ -191,18 +198,6 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
191
198
|
ctx.status(statusCode);
|
|
192
199
|
}
|
|
193
200
|
|
|
194
|
-
const responseContentType = await this.getHeader(ctx, 'Content-Type');
|
|
195
|
-
|
|
196
|
-
if (
|
|
197
|
-
!responseContentType?.startsWith('application/json') &&
|
|
198
|
-
body?.statusCode >= HttpStatus.BAD_REQUEST
|
|
199
|
-
) {
|
|
200
|
-
Logger.warn(
|
|
201
|
-
"Content-Type doesn't match Reply body, you might need a custom ExceptionFilter for non-JSON responses",
|
|
202
|
-
);
|
|
203
|
-
this.setHeader(ctx, 'Content-Type', 'application/json');
|
|
204
|
-
}
|
|
205
|
-
|
|
206
201
|
ctx.res = await this.getBody(ctx, body);
|
|
207
202
|
}
|
|
208
203
|
|