JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1713
  • Score
    100M100P100Q116289F
  • License MIT

Restart Fastify without losing a request

Package Exports

  • @fastify/restartable
  • @fastify/restartable/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@fastify/restartable) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@fastify/restartable

Restart Fastify without losing a request.

This module is useful if you want to compose the fastify routes dynamically or you need some remote config. In case of a change, you can restart Fastify.

Install

npm i @fastify/restartable

Usage

import { start } from '@fastify/restartable'

async function myApp (app, opts) {
  // opts are the options passed to start()
  console.log('plugin loaded', opts)

  app.get('/restart', async (req, reply) => {
    await app.restart()
    return { status: 'ok' }
  })
}

const { stop, restart, listen, inject } = await start({
  protocol: 'http', // or 'https'
  // key: ...,
  // cert: ...,
  // add all other options that you would pass to fastify
  hostname: '127.0.0.1',
  port: 3000,
  app: myApp
})

const { address, port } = await listen()

console.log('server listening on', address, port)
// call restart() if you want to restart
// call restart(newOpts) if you want to restart Fastify with new options
// you can't change all the protocol details.

// call inject() to inject a request, see Fastify docs

License

MIT