@kiyasov/platform-hono 1.2.1 → 1.2.4

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.4",
4
4
  "description": "Nest adapter for Hono",
5
5
  "author": "Islam Kiiasov",
6
6
  "repository": {
@@ -210,19 +210,31 @@ 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
 
218
224
  switch (type) {
219
225
  case "application/json":
220
- if (contentType?.startsWith("application/json"))
226
+ if (contentType?.startsWith("application/json")) {
227
+ if (rawBody) {
228
+ (ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
229
+ }
221
230
  (ctx.req as any).body = await ctx.req.json();
231
+ }
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());
235
+ if (rawBody) {
236
+ (ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
237
+ }
226
238
  (ctx.req as any).body = await ctx.req.json();
227
239
  }
228
240
  break;
@@ -258,15 +270,15 @@ export class HonoAdapter extends AbstractHttpAdapter<
258
270
  return "hono";
259
271
  }
260
272
 
261
- public registerParserMiddleware(prefix?: string, rawBody?: boolean) {
273
+ public registerParserMiddleware(_prefix?: string, rawBody?: boolean) {
262
274
  if (this._isParserRegistered) {
263
275
  return;
264
276
  }
265
277
 
266
278
  Logger.log("Registering parser middleware");
267
- this.useBodyParser("application/x-www-form-urlencoded");
268
- this.useBodyParser("application/json");
269
- this.useBodyParser("text/plain");
279
+ this.useBodyParser("application/x-www-form-urlencoded", rawBody);
280
+ this.useBodyParser("application/json", rawBody);
281
+ this.useBodyParser("text/plain", rawBody);
270
282
 
271
283
  this._isParserRegistered = true;
272
284
  }