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

1.11.0 • Public • Published

@purista/httpserver

[!CAUTION] 🚨 This Package is deprecated and maintenance will end soon. 🚨 Please migrate to @purista/hono-http-server package.

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

While the main focus is on development and debug, the HttpServerService will also fit for small projects or running on IoT/edge.

Under the hood, fastify is used as basement. Because of this, the whole fastify ecosystem can be used and integrated.

The HttpServerService can also be configured, to provide the OpenApi-UI in browsers. The OpenApi definitions is created from the CommandBuilder settings of each command. This means, that there are no additional steps or code required, to provide the OpenApi definition. It is autogenerated mostly from input and output schema definitions.

Example usage:

import fastifyStatic from '@fastify/static'
import { DefaultEventBridge, gracefulShutdown, initLogger } from '@purista/core'
import { httpServerV1Service, HttpServerServiceV1Config } from '@purista/httpserver'

const main = async() => {
  const logger = initLogger()

  const eventBridge = new DefaultEventBridge()

  const httpServerConfig: HttpServerServiceV1Config = {
    fastify: {},
    port: 8080,
    logLevel: 'debug',
    domain: 'localhost',
    apiMountPath: '/api',
    openApi: {
      enabled: true,
      info: {
        title: 'backend api',
        description: 'OpenApi definition for server endpoints',
        version: '1.0.0',
      },
    },
  }

  const httpServerService = await httpServerV1Service.getInstance(eventBridge, {
    serviceConfig: httpServerConfig,
  })

  // static file handler
  const defaultPublicPath = resolve(__dirname, '..', 'public')
  httpServerService.server?.register(fastifyStatic, {
    root: defaultPublicPath,
    decorateReply: false,
  })

  // start the webserver
  await httpServerService.start()

  // and and start your services here
  // ...
  // ...

  gracefulShutdown(logger, [
    // start with the event bridge to no longer accept incoming messages
    eventBridge,
    // shut down optional services
    // ...
    // ...
    httpServerService,
  ])
}

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/httpserver

Homepage

purista.dev

Weekly Downloads

60

Version

1.11.0

License

ISC

Unpacked Size

198 kB

Total Files

154

Last publish

Collaborators

  • sebastianwessel