1.11.0 • Published 1 year ago

@purista/hono-http-server v1.11.0

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

@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

1.11.0

1 year ago

1.10.8

1 year ago

1.10.7

1 year ago

1.10.5

1 year ago

1.10.4

1 year ago

1.10.6

1 year ago

1.10.3

1 year ago

1.10.2

1 year ago

1.10.1

1 year ago

1.10.0

1 year ago

1.9.1

1 year ago