@kiyasov/platform-hono 1.3.9 → 1.3.10

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.9",
3
+ "version": "1.3.10",
4
4
  "description": "Nest adapter for Hono",
5
5
  "author": "Islam Kiiasov",
6
6
  "repository": {
@@ -126,7 +126,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
126
126
  public async reply(ctx: Context, body: any, statusCode?: StatusCode) {
127
127
  if (statusCode) ctx.status(statusCode);
128
128
 
129
- const responseContentType = this.getHeader(ctx, "Content-Type");
129
+ const responseContentType = await this.getHeader(ctx, "Content-Type");
130
130
  if (
131
131
  !responseContentType?.startsWith("application/json") &&
132
132
  body?.statusCode >= HttpStatus.BAD_REQUEST
@@ -205,8 +205,19 @@ export class HonoAdapter extends AbstractHttpAdapter<
205
205
  return true;
206
206
  }
207
207
 
208
- public getHeader?(ctx: Context, name: string) {
209
- return ctx.req.header(name);
208
+ public async getHeader?(
209
+ ctx: Context | (() => Promise<Context>),
210
+ name: string
211
+ ) {
212
+ if (typeof ctx === "function") {
213
+ ctx = await ctx();
214
+ }
215
+
216
+ if (ctx && typeof ctx.req.header === "function") {
217
+ return ctx.req.header(name);
218
+ } else {
219
+ throw new Error("Invalid context: get method not found on context.");
220
+ }
210
221
  }
211
222
 
212
223
  public async setHeader(
@@ -241,8 +252,16 @@ export class HonoAdapter extends AbstractHttpAdapter<
241
252
  }
242
253
  }
243
254
 
244
- public getRequestHostname(ctx: Context): string {
245
- return ctx.req.header().host;
255
+ public async getRequestHostname(ctx: Context | (() => Promise<Context>)) {
256
+ if (typeof ctx === "function") {
257
+ ctx = await ctx();
258
+ }
259
+
260
+ if (ctx && typeof ctx.req.header === "function") {
261
+ return ctx.req.header("host");
262
+ } else {
263
+ throw new Error("Invalid context: get method not found on context.");
264
+ }
246
265
  }
247
266
 
248
267
  public getRequestMethod(request: HonoRequest): string {