1.5.1 • Published 1 year ago

@kiyasov/platform-hono v1.5.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Hono NestJS Adapter

NPM version NPM Downloads

This package allows you to use Hono with the NestJS framework.

Components

  • HonoAdapter: Adapter to use Hono with NestJS.

How to Use

Setup

To install @kiyasov/platform-hono:

npm install @kiyasov/platform-hono
# or
yarn add @kiyasov/platform-hono

Create Application

import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { HonoAdapter } from "@kiyasov/platform-hono";

const app = await NestFactory.create<NestHonoApplication>(
  AppModule,
  new HonoAdapter()
);

Exception filters

import {
  ExceptionFilter,
  Catch,
  ArgumentsHost,
  HttpException,
  HttpStatus,
} from "@nestjs/common";
import { HttpAdapterHost } from "@nestjs/core";

@Catch()
export class AllExceptionsFilter implements ExceptionFilter {
  constructor(private readonly httpAdapterHost: HttpAdapterHost) {}

  catch(exception: unknown, host: ArgumentsHost): void {
    const { httpAdapter } = this.httpAdapterHost;

    const ctx = host.switchToHttp();

    const httpStatus =
      exception instanceof HttpException
        ? exception.getStatus()
        : HttpStatus.INTERNAL_SERVER_ERROR;

    const responseBody = {
      statusCode: httpStatus,
      timestamp: new Date().toISOString(),
      path: httpAdapter.getRequestUrl(ctx.getRequest()),
    };

    httpAdapter.reply(ctx.getResponse(), responseBody, httpStatus);
  }
}
1.4.6

1 year ago

1.4.5

1 year ago

1.4.4

1 year ago

1.4.3

1 year ago

1.4.2

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.17

1 year ago

1.3.18

1 year ago

1.3.15

2 years ago

1.3.16

1 year ago

1.3.19

1 year ago

1.3.20

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.7

1 year ago

1.3.14

2 years ago

1.3.12

2 years ago

1.3.10

2 years ago

1.3.11

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.9

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago