@kiyasov/platform-hono 1.3.2 → 1.3.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.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Nest adapter for Hono",
5
5
  "author": "Islam Kiiasov",
6
6
  "repository": {
@@ -218,39 +218,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
218
218
  Logger.log(
219
219
  `Registering body parser middleware for type: ${type} | bodyLimit: ${bodyLimit}`
220
220
  );
221
- this.instance.use(this.bodyLimit(bodyLimit), async (ctx, next) => {
222
- const contentType = ctx.req.header("content-type");
223
-
224
- if (
225
- contentType?.startsWith("application/json") ||
226
- contentType?.startsWith("text/plain")
227
- ) {
228
- if (rawBody) {
229
- (ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
230
- }
231
- (ctx.req as any).body = await ctx.req.json();
232
-
233
- return await next();
234
- }
235
-
236
- if (contentType !== type) {
237
- return await next();
238
- }
239
-
240
- if (contentType?.startsWith("application/json")) {
241
- if (rawBody) {
242
- (ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
243
- }
244
- (ctx.req as any).body = await ctx.req.json();
245
- } else if (contentType?.startsWith("text/plain")) {
246
- if (rawBody) {
247
- (ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
248
- }
249
- (ctx.req as any).body = await ctx.req.json();
250
- }
251
-
252
- return await next();
253
- });
221
+ this.instance.use(this.bodyLimit(bodyLimit));
254
222
 
255
223
  // To avoid the Nest application init to override our custom
256
224
  // body parser, we mark the parsers as registered.
@@ -262,7 +230,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
262
230
  }
263
231
 
264
232
  public initHttpServer(options: NestApplicationOptions) {
265
- this.instance.use((ctx, next) => {
233
+ this.instance.use(async (ctx, next) => {
266
234
  ctx.req["ip"] =
267
235
  ctx.req.header("cf-connecting-ip") ??
268
236
  ctx.req.header("x-forwarded-for") ??
@@ -277,6 +245,23 @@ export class HonoAdapter extends AbstractHttpAdapter<
277
245
  ctx.req["query"] = ctx.req.query() as any;
278
246
  ctx.req["headers"] = Object.fromEntries(ctx.req.raw.headers);
279
247
 
248
+ const contentType = ctx.req.header("content-type");
249
+
250
+ if (
251
+ contentType?.startsWith("multipart/form-data") ||
252
+ contentType?.startsWith("application/x-www-form-urlencoded")
253
+ ) {
254
+ (ctx.req as any).body = await ctx.req.parseBody();
255
+ } else if (
256
+ contentType?.startsWith("application/json") ||
257
+ contentType?.startsWith("text/plain")
258
+ ) {
259
+ if (options.rawBody) {
260
+ (ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
261
+ }
262
+ (ctx.req as any).body = await ctx.req.json();
263
+ }
264
+
280
265
  return next();
281
266
  });
282
267
  const isHttpsEnabled = options?.httpsOptions;