gajus / lightship

Abstracts readiness, liveness and startup checks and graceful shutdown of Node.js services running in Kubernetes.
Other
517 stars 33 forks source link

Lightship with inversify-express-utils #17

Closed WandersonAlves closed 4 years ago

WandersonAlves commented 4 years ago

Hi Gajus! Thanks for creating this lib!

I was trying to make it work in my current stack, but none of /health, /live and /ready routes work. Today, i use https://github.com/inversify/inversify-express-utils to handle my express application. I was following the README.md but i couldn't make it work :(

Below is my index.ts:

import 'reflect-metadata';
import * as mongoose from 'mongoose';
import * as sourceMapSupport from 'source-map-support';
import { createLightship } from 'lightship';
import { delay } from 'bluebird';
import { InversifyExpressServer } from 'inversify-express-utils';
import Connection from './shared/class/Connection';
import env from './config/env';
import injectionContainer from './config/inversify.config';
import middleware from './shared/middlewares';
import REFERENCES from './config/inversify.references';

mongoose.set('useNewUrlParser', true);
mongoose.set('useCreateIndex', true);
mongoose.set('useUnifiedTopology', true);

sourceMapSupport.install();
process.on('unhandledRejection', console.log);

const server = new InversifyExpressServer(injectionContainer);
const mongoConn = injectionContainer.get<Connection>(REFERENCES.Connection);

server.setConfig(app => {
  middleware.initMiddlewares(app);
  middleware.initCustomRoutes(app);
});

server.setErrorConfig(app => {
  middleware.initExceptionMiddlewares(app);
});

const bootstrapedServer = server.build();

bootstrapedServer.listen(env.server_port, async () => {
  await mongoConn.connect();
  lightship.signalReady();
  console.log(`Opening the gates in ${env.server_port}`);
});

const lightship = createLightship();
lightship.registerShutdownHandler(async () => {
  await delay(30 * 1000);
  await mongoConn.disconnect();
});

I didn't find how to send a reference of my express app to lightship. This is possible?

Thanks!

gajus commented 4 years ago

Cannot provide help with code reviews.

Please pose a specific issue/ bug.