@purista/hono-http-server
TypeScript icon, indicating that this package has built-in type declarations

1.11.0 • Public • Published

@purista/hono-http-server

The HonoService is a service which exposes commands of services as http endpoints. All exposed commands must be marked as exposed endpoints in the CommandBuilder.

Under the hood, Hono is used as basement.

Example usage:

import { serve } from '@hono/node-server'
import { swaggerUI } from '@hono/swagger-ui'
import { DefaultEventBridge } from '@purista/core'
import { honoV1Service } from '@purista/hono-http-server'
import { basicAuth } from 'hono/basic-auth'
import { compress } from 'hono/compress'

import { pingV1Service } from './service/ping/v1/index.js'

export const main = async () => {
  // initiate the event bridge as first step
  const eventBridge = new DefaultEventBridge()
  await eventBridge.start()

  // add your service
  const pingService = await pingV1Service.getInstance(eventBridge)
  await pingService.start()

  // initiate the webserver service as second step
  const honoService = await honoV1Service.getInstance(eventBridge, { serviceConfig: { services: [pingService] } })

  honoService.app.use('*', compress())
  honoService.app.get('/api', swaggerUI({ url: '/api/openapi.json' }))
  honoService.openApi.addSecurityScheme('basicAuth', { type: 'http', scheme: 'basic' })
  honoService.openApi.addServer({ url: 'http://localhost:3000', description: 'the local server' })

  honoService.setHealthFunction(async function () {
    this.logger.info('custom health check')
  })

  honoService.setProtectHandler(async function (c, next) {
    const auth = basicAuth({ username: 'user', password: 'password' })
    return auth(c, next)
  })

  // start the webserver service
  await honoService.start()

  // open socket
  const _serverInstance = serve({
    fetch: honoService.app.fetch,
    port: 3000,
  })
}

main()

Visit purista.dev

Follow on Twitter @purista_js
Join the Discord Chat

PURISTA - Typescript framework for IoT, microservices, and serverless | Product Hunt

Readme

Keywords

none

Package Sidebar

Install

npm i @purista/hono-http-server

Homepage

purista.dev

Weekly Downloads

131

Version

1.11.0

License

ISC

Unpacked Size

160 kB

Total Files

148

Last publish

Collaborators

  • sebastianwessel