4.13.108 • Published 10 months ago

@patrtorg/pariatur-sapiente v4.13.108

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@patrtorg/pariatur-sapiente

NPM version CI js-standard-style

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 @patrtorg/pariatur-sapiente

Usage

import { restartable } from '@patrtorg/pariatur-sapiente'

async function createApp (fastify, opts) {
  const app = fastify(opts)

  app.get('/restart', async () => {
    await app.restart()
    return { status: 'ok' }
  })
  
  app.addHook('onClose', async () => {
    if(!app.closingRestartable) {
      console.log('closing the app because of restart')
    }
    else{
      console.log('closing the app because server is stopping')
    }
  })
  
  return app
}

const app = await restartable(createApp, { logger: true })
const host = await app.listen({ port: 3000 })

console.log('server listening on', host)

// call restart() if you want to restart
process.on('SIGUSR1', () => {
  console.log('Restarting the server')
  app.restart()
})

process.once('SIGINT', () => {
  console.log('Stopping the server')
  app.close()
})

Hooks

  • preRestart - called before the creating a new app instance and closing an existing one. The hook is called with the current app instance as an argument. Use it to close any resources that you don't want to be shared between the app instances.

  • onRestart - called after the new app instance is created and the old one is closed. The hook is called with the new app instance as an argument.

Example:

  async function createApplication (fastify, opts) {
    console.log('creating new app instance')
    return fastify(opts)
  }
  const app = await restartable(createApplication)

  app.addPreRestartHook(async (app) => {
    console.log('preRestart hook called')
  })
  
  app.addOnRestartHook(async (app) => {
    console.log('onRestart hook called')
  })

  await app.restart()

Output:

preRestart hook called
creating new app instance
onRestart hook called

License

MIT

posetoArrayfastcloneCSSStyleDeclarationtypescriptredactelectronMapESUint32ArrayfastifypathistanbulESnextutil.inspectstylemruECMAScript 2022graphqlFunction.prototype.namearktypexmlfromflages6call-bindapiECMAScriptECMAScript 3routeutilitygetintrinsicbyteOffsetisConcatSpreadablesortedkeysArray.prototype.includestrimEndwidthstringifyconfigurableintrinsicsameValueZerospecObservablestylesnopecoredebuggercss-in-jsObject.valuesworkflowlistenersrdsCSSES5private datatslibfunctioncheckclirfc4122wafclassnamesform-validationcode pointsfull-widthstarterconsumeassertfast-copyreadablestreamcallbackmovestreamparentsxtermlastpinotermfastcoercibleiterateincludeslookerroruser-streamsaccessorminimaljasmineprocessSymbolnegative zerosuperagentignorechaieventEmittermkdirsdefinePropertyeast-asian-widthObject.entriesmergetyped arraystringcommandtypanionsorthttpstc39l10ns3bindamazonargumenttextqsArrayBufferdependency manageroptimisttrimboundES8dom-testing-libraryreact-hook-formpurebyteLengthcollectiones2018randomString.prototype.matchAllbusymonorepodaterobustassignhigher-orderwritablebuffers_.extendreduceselfsafeendpointjson-schema-validationcompilertypedbeanstalkES3optionhelpersdragimportcompareeslint-pluginglobal objectES2017WebSocketsjsonschemafantasy-landwarningpopmotionreversedspawnfigletstructuredClonejapaneseindicatores8ES2023propertygetPrototypeOfObject.definePropertycloudwatchyupES6hooksviewgetairbnbswfidlequeueMicrotaskautoscalingguidartsource maptoStringTagArray.prototype.findLastIndexshellimportexportenumerableimmermanipulationformsRFC-6455i18ntoolssqssomeeslintconfigdirrapidhases7pruneRegExp.prototype.flagsrgbflatspringpropWeakMaptypefast-cloneES2018String.prototype.trimwindowglobalsfixed-widthinternal slotBigInt64ArrayhasOwncloudfrontUint16ArrayreworkidentifiersArray.prototype.filtercirculardata
4.13.107

10 months ago

4.13.108

10 months ago

4.13.106

10 months ago

4.13.105

10 months ago

4.12.105

10 months ago

4.12.104

10 months ago

4.12.103

10 months ago

4.12.102

10 months ago

4.12.101

10 months ago

4.12.100

10 months ago

4.12.99

10 months ago

4.12.98

10 months ago

4.12.97

10 months ago

4.12.96

10 months ago

4.12.95

10 months ago

4.12.94

10 months ago

4.12.93

10 months ago

4.11.93

10 months ago

4.11.92

10 months ago

4.11.91

10 months ago

4.11.90

10 months ago

4.11.89

10 months ago

3.11.89

10 months ago

3.11.88

11 months ago

3.10.88

11 months ago

3.9.88

11 months ago

3.9.87

11 months ago

3.9.86

11 months ago

3.9.85

11 months ago

3.9.84

11 months ago

3.9.83

11 months ago

3.8.83

11 months ago

3.8.82

11 months ago

3.7.82

11 months ago

3.7.81

11 months ago

3.7.80

11 months ago

3.7.79

11 months ago

3.7.78

11 months ago

3.7.77

11 months ago

3.7.76

11 months ago

3.7.75

11 months ago

2.7.75

11 months ago

2.7.74

11 months ago

2.7.73

11 months ago

2.7.72

11 months ago

2.7.71

11 months ago

2.7.70

11 months ago

2.7.69

11 months ago

2.7.68

11 months ago

2.7.67

11 months ago

2.7.66

11 months ago

2.7.65

11 months ago

2.7.64

11 months ago

2.7.63

12 months ago

2.7.62

12 months ago

2.7.61

12 months ago

2.7.60

12 months ago

2.7.59

12 months ago

2.7.58

12 months ago

2.7.57

12 months ago

2.7.56

12 months ago

2.7.55

12 months ago

2.7.54

12 months ago

1.7.54

12 months ago

1.7.53

12 months ago

1.7.52

12 months ago

1.7.51

12 months ago

1.7.50

12 months ago

1.7.49

12 months ago

1.7.48

12 months ago

1.6.48

12 months ago

1.6.47

12 months ago

1.6.46

12 months ago

1.6.45

1 year ago

1.6.44

1 year ago

1.6.43

1 year ago

1.6.42

1 year ago

1.6.41

1 year ago

1.6.40

1 year ago

1.6.39

1 year ago

1.6.38

1 year ago

1.5.38

1 year ago

1.5.37

1 year ago

1.5.36

1 year ago

1.5.35

1 year ago

1.4.35

1 year ago

1.4.34

1 year ago

1.4.33

1 year ago

1.3.33

1 year ago

1.3.32

1 year ago

1.2.32

1 year ago

1.2.31

1 year ago

1.2.30

1 year ago

1.2.29

1 year ago

1.2.28

1 year ago

1.2.27

1 year ago

1.2.26

1 year ago

1.2.25

1 year ago

1.2.24

1 year ago

1.2.23

1 year ago

1.2.22

1 year ago

1.2.21

1 year ago

1.2.20

1 year ago

1.1.20

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago