@kiyasov/platform-hono 1.1.8 → 1.2.0

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/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@kiyasov/platform-hono",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "Nest adapter for Hono",
5
5
  "author": "Islam Kiiasov",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/kiyasov/platform-hono"
9
+ },
6
10
  "license": "MIT",
7
11
  "main": "./dist/cjs/index.js",
8
12
  "module": "./dist/esm/index.js",
@@ -36,11 +36,16 @@ export class HonoAdapter extends AbstractHttpAdapter<
36
36
  Context
37
37
  > {
38
38
  protected readonly instance: Hono<{ Bindings: HttpBindings }>;
39
+ private _isParserRegistered: boolean;
39
40
 
40
41
  constructor() {
41
42
  super(new Hono());
42
43
  }
43
44
 
45
+ get isParserRegistered(): boolean {
46
+ return !!this._isParserRegistered;
47
+ }
48
+
44
49
  private getRouteAndHandler(
45
50
  pathOrHandler: string | HonoHandler,
46
51
  handler?: HonoHandler
@@ -209,6 +214,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
209
214
  Logger.log("Registering body parser middleware");
210
215
  this.instance.use(this.bodyLimit(bodyLimit), async (ctx, next) => {
211
216
  const contentType = ctx.req.header("content-type");
217
+
212
218
  switch (type) {
213
219
  case "application/json":
214
220
  if (contentType?.startsWith("application/json"))
@@ -226,6 +232,10 @@ export class HonoAdapter extends AbstractHttpAdapter<
226
232
  }
227
233
  await next();
228
234
  });
235
+
236
+ // To avoid the Nest application init to override our custom
237
+ // body parser, we mark the parsers as registered.
238
+ this._isParserRegistered = true;
229
239
  }
230
240
 
231
241
  public close(): Promise<void> {
@@ -249,10 +259,16 @@ export class HonoAdapter extends AbstractHttpAdapter<
249
259
  }
250
260
 
251
261
  public registerParserMiddleware(prefix?: string, rawBody?: boolean) {
262
+ if (this._isParserRegistered) {
263
+ return;
264
+ }
265
+
252
266
  Logger.log("Registering parser middleware");
253
267
  this.useBodyParser("application/x-www-form-urlencoded");
254
268
  this.useBodyParser("application/json");
255
269
  this.useBodyParser("text/plain");
270
+
271
+ this._isParserRegistered = true;
256
272
  }
257
273
 
258
274
  public async createMiddlewareFactory(requestMethod: RequestMethod) {