@kiyasov/platform-hono 1.2.1 → 1.2.3

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiyasov/platform-hono",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "Nest adapter for Hono",
5
5
  "author": "Islam Kiiasov",
6
6
  "repository": {
@@ -210,11 +210,21 @@ export class HonoAdapter extends AbstractHttpAdapter<
210
210
  this.instance.use(cors(options));
211
211
  }
212
212
 
213
- public useBodyParser(type: TypeBodyParser, bodyLimit: number = 1e6) {
214
- Logger.log("Registering body parser middleware");
213
+ public useBodyParser(
214
+ type: TypeBodyParser,
215
+ rawBody?: boolean,
216
+ bodyLimit?: number
217
+ ) {
218
+ Logger.log(
219
+ `Registering body parser middleware for type: ${type} | bodyLimit: ${bodyLimit}`
220
+ );
215
221
  this.instance.use(this.bodyLimit(bodyLimit), async (ctx, next) => {
216
222
  const contentType = ctx.req.header("content-type");
217
223
 
224
+ if (rawBody) {
225
+ (ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
226
+ }
227
+
218
228
  switch (type) {
219
229
  case "application/json":
220
230
  if (contentType?.startsWith("application/json"))
@@ -222,7 +232,6 @@ export class HonoAdapter extends AbstractHttpAdapter<
222
232
  break;
223
233
  case "text/plain":
224
234
  if (contentType?.startsWith("text/plain")) {
225
- (ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
226
235
  (ctx.req as any).body = await ctx.req.json();
227
236
  }
228
237
  break;
@@ -258,15 +267,15 @@ export class HonoAdapter extends AbstractHttpAdapter<
258
267
  return "hono";
259
268
  }
260
269
 
261
- public registerParserMiddleware(prefix?: string, rawBody?: boolean) {
270
+ public registerParserMiddleware(_prefix?: string, rawBody?: boolean) {
262
271
  if (this._isParserRegistered) {
263
272
  return;
264
273
  }
265
274
 
266
275
  Logger.log("Registering parser middleware");
267
- this.useBodyParser("application/x-www-form-urlencoded");
268
- this.useBodyParser("application/json");
269
- this.useBodyParser("text/plain");
276
+ this.useBodyParser("application/x-www-form-urlencoded", rawBody);
277
+ this.useBodyParser("application/json", rawBody);
278
+ this.useBodyParser("text/plain", rawBody);
270
279
 
271
280
  this._isParserRegistered = true;
272
281
  }