1.11.0 • Published 2 months ago

@purista/httpserver v1.11.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

@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

1.11.0

2 months ago

1.10.8

2 months ago

1.10.7

3 months ago

1.10.5

3 months ago

1.10.4

3 months ago

1.10.6

3 months ago

1.10.3

3 months ago

1.10.2

3 months ago

1.10.1

3 months ago

1.10.0

3 months ago

1.9.1

3 months ago

1.7.3

10 months ago

1.9.0

6 months ago

1.8.1

8 months ago

1.8.0

8 months ago

1.7.5

10 months ago

1.8.3

7 months ago

1.7.4

10 months ago

1.7.2

11 months ago

1.7.1

11 months ago

1.7.0

11 months ago

1.6.0

12 months ago

1.5.0

1 year ago

1.4.9

1 year ago

1.4.8

2 years ago

1.4.7

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago