@kiyasov/platform-hono 1.2.3 → 1.2.5

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.
Files changed (30) hide show
  1. package/dist/cjs/src/adapters/hono-adapter.d.ts +2 -3
  2. package/dist/cjs/src/adapters/hono-adapter.js +12 -4
  3. package/dist/cjs/src/adapters/hono-adapter.js.map +1 -1
  4. package/dist/cjs/src/interfaces/hono.d.ts +4 -0
  5. package/dist/cjs/src/interfaces/hono.interface.d.ts +4 -0
  6. package/dist/cjs/src/interfaces/hono.interface.js +3 -0
  7. package/dist/cjs/src/interfaces/hono.interface.js.map +1 -0
  8. package/dist/cjs/src/interfaces/hono.js +3 -0
  9. package/dist/cjs/src/interfaces/hono.js.map +1 -0
  10. package/dist/cjs/src/interfaces/index.d.ts +2 -1
  11. package/dist/cjs/src/interfaces/index.js +1 -0
  12. package/dist/cjs/src/interfaces/index.js.map +1 -1
  13. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  14. package/dist/esm/src/adapters/hono-adapter.d.ts +2 -3
  15. package/dist/esm/src/adapters/hono-adapter.js +12 -4
  16. package/dist/esm/src/adapters/hono-adapter.js.map +1 -1
  17. package/dist/esm/src/interfaces/hono.d.ts +4 -0
  18. package/dist/esm/src/interfaces/hono.interface.d.ts +4 -0
  19. package/dist/esm/src/interfaces/hono.interface.js +2 -0
  20. package/dist/esm/src/interfaces/hono.interface.js.map +1 -0
  21. package/dist/esm/src/interfaces/hono.js +2 -0
  22. package/dist/esm/src/interfaces/hono.js.map +1 -0
  23. package/dist/esm/src/interfaces/index.d.ts +2 -1
  24. package/dist/esm/src/interfaces/index.js +2 -1
  25. package/dist/esm/src/interfaces/index.js.map +1 -1
  26. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  27. package/package.json +1 -1
  28. package/src/adapters/hono-adapter.ts +14 -8
  29. package/src/interfaces/hono.interface.ts +5 -0
  30. package/src/interfaces/index.ts +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiyasov/platform-hono",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Nest adapter for Hono",
5
5
  "author": "Islam Kiiasov",
6
6
  "repository": {
@@ -14,14 +14,13 @@ import {
14
14
  serveStatic,
15
15
  } from "@hono/node-server/serve-static";
16
16
  import { AbstractHttpAdapter } from "@nestjs/core/adapters/http-adapter";
17
- import { Context, HonoRequest, Next } from "hono";
18
- import { Hono } from "hono";
17
+ import { Context, Next, Hono } from "hono";
19
18
  import { cors } from "hono/cors";
20
19
  import { RedirectStatusCode, StatusCode } from "hono/utils/http-status";
21
20
  import * as http from "http";
22
21
  import { Http2SecureServer, Http2Server } from "http2";
23
22
  import * as https from "https";
24
- import { TypeBodyParser } from "../interfaces";
23
+ import { HonoRequest, TypeBodyParser } from "../interfaces";
25
24
 
26
25
  type HonoHandler = RequestHandler<HonoRequest, Context>;
27
26
 
@@ -221,17 +220,20 @@ export class HonoAdapter extends AbstractHttpAdapter<
221
220
  this.instance.use(this.bodyLimit(bodyLimit), async (ctx, next) => {
222
221
  const contentType = ctx.req.header("content-type");
223
222
 
224
- if (rawBody) {
225
- (ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
226
- }
227
-
228
223
  switch (type) {
229
224
  case "application/json":
230
- if (contentType?.startsWith("application/json"))
225
+ if (contentType?.startsWith("application/json")) {
226
+ if (rawBody) {
227
+ (ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
228
+ }
231
229
  (ctx.req as any).body = await ctx.req.json();
230
+ }
232
231
  break;
233
232
  case "text/plain":
234
233
  if (contentType?.startsWith("text/plain")) {
234
+ if (rawBody) {
235
+ (ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
236
+ }
235
237
  (ctx.req as any).body = await ctx.req.json();
236
238
  }
237
239
  break;
@@ -252,6 +254,10 @@ export class HonoAdapter extends AbstractHttpAdapter<
252
254
  }
253
255
 
254
256
  public initHttpServer(options: NestApplicationOptions) {
257
+ this.instance.use((ctx, next) => {
258
+ ctx.req["headers"] = Object.fromEntries(ctx.req.raw.headers);
259
+ return next();
260
+ });
255
261
  const isHttpsEnabled = options?.httpsOptions;
256
262
  const createServer = isHttpsEnabled
257
263
  ? https.createServer
@@ -0,0 +1,5 @@
1
+ import { HonoRequest as Request } from "hono";
2
+
3
+ export type HonoRequest = Request & {
4
+ headers?: Record<string, string>;
5
+ };
@@ -1 +1,2 @@
1
- export * from './nest-hono-application.interface';
1
+ export * from "./nest-hono-application.interface";
2
+ export * from "./hono.interface";