From a8f4c889fe363fa457258626eede34221479a2ba Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Tue, 25 Jun 2019 19:17:02 -0700 Subject: [PATCH] Bring in the common function for starting all feathers applications --- lib/src/server.ts | 29 +++++++++++++++++++++++++++++ services/orchestrator/src/index.ts | 2 ++ tsconfig.base.json | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 lib/src/server.ts diff --git a/lib/src/server.ts b/lib/src/server.ts new file mode 100644 index 0000000..dc93b5a --- /dev/null +++ b/lib/src/server.ts @@ -0,0 +1,29 @@ +/** + * This module acts as the simple wrapper for serving any feathers application + * in the project + */ + +import logger from '@otto/logger'; + +import { Application } from '@feathersjs/express'; + +/** + * The serveApp function expects a Feathers application which it can start + * serving on its configured port + * + * This method is *asynchronous* and will not return a success or fail + * + * @param app An instantiated feathers application + */ +export function serveApp(app: Application) { + const port: Number = app.get('port'); + const server: any = app.listen(port); + + process.on('unhandledRejection', (reason, p) => + logger.error('Unhandled Rejection at: Promise ', p, reason) + ); + + server.on('listening', () => + logger.info('Feathers application started on http://%s:%d', app.get('host'), port) + ); +} diff --git a/services/orchestrator/src/index.ts b/services/orchestrator/src/index.ts index 9a9d551..69a6ffc 100644 --- a/services/orchestrator/src/index.ts +++ b/services/orchestrator/src/index.ts @@ -1,4 +1,6 @@ require('module-alias/register'); + import logger from '@otto/logger'; +import { serveApp } from '@otto/server' logger.info('Starting orchestrator'); diff --git a/tsconfig.base.json b/tsconfig.base.json index 587782d..c835aff 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -13,7 +13,7 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, - "noUnusedLocals": true, + "noUnusedLocals": false, "strictNullChecks": true, "skipLibCheck": true,