How to use lightship - 3 common examples

To help you get started, we’ve selected a few lightship examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lifechurch / melos / elaphros / server.js View on Github external
fastify.register(require('./decorators/raven-decorator'))
fastify.register(require('./decorators/bible-versions-decorator'), { timeout: 0 })
fastify.register(require('./decorators/bible-config-decorator'), { timeout: 0 })

// Plugins
fastify.register(require('./plugins/cors'))
fastify.register(require('./plugins/redirect-authenticated'))
fastify.register(require('./plugins/manifest'))
fastify.register(require('./plugins/service-worker'))
fastify.register(require('./plugins/i18n'))
fastify.register(require('./plugins/bible-versions'))
fastify.register(require('./plugins/bible'))
fastify.register(require('./plugins/confirmations'))
fastify.register(require('./plugins/main'))

const lightship = createLightship()

fastify.log.info('Registering shutdown handler via Lightship')
lightship.registerShutdownHandler(() => {
  fastify.log.info('Shutting down Fastify server via registered Lightship handler.')
  fastify.close()
})

/* Start Listening on PORT */
const PORT = process.env.PORT || 3030
fastify.listen(PORT, '0.0.0.0', (err) => {
  if (err) {
    fastify.captureException(err, 'Error starting Fastify server: ')
    process.exit(1)
  }
  lightship.signalReady()
  fastify.log.info(`Server started listening on ${fastify.server.address().port}`)
github lifechurch / melos / nodejs / bin / www.js View on Github external
/* global PhusionPassenger */
/* eslint-disable no-console */

const app = require('../app');
const debug = require('debug')('youversion-events:server');
const http = require('http');
const { createLightship } = require('lightship')

const lightship = createLightship()

/**
* Get port from environment and store in Express.
*/
module.exports = function startNodeWWW() {
  if (typeof (PhusionPassenger) !== 'undefined') {
    PhusionPassenger.configure({ autoInstall: false });
  }

  /**
  * Normalize a port into a number, string, or false.
  */
  const normalizePort = (val) => {
    if (typeof (PhusionPassenger) !== 'undefined') {
      return 'passenger'
    } else {
github commercetools / merchant-center-application-kit / packages / mc-http-server / server.js View on Github external
const createLightshipServer = options => {
  const lightship = createLightship({
    detectKubernetes: true,
    ...options,
  });
  lightship.registerShutdownHandler(async () => {
    /**
     * NOTE: The default k8s grace period is 60 seconds. It is often
     * recommended to not exceed the grace period given by k8s by half.
     * 20 seconds is chosen here under the assumption that any outstanging
     * request just settle by then.
     */
    await new Promise(resolve => setTimeout(resolve, 20000));

    signalIsNotUp();

    if (applicationServer) applicationServer.close();
    if (prometheusMetricsServer) prometheusMetricsServer.close();

lightship

Abstracts readiness, liveness and startup checks and graceful shutdown of Node.js services running in Kubernetes.

BSD-3-Clause
Latest version published 8 months ago

Package Health Score

64 / 100
Full package analysis

Popular lightship functions