From 38b39ce2d276629d70cfa4d08f8c4c33f2d9b7cd Mon Sep 17 00:00:00 2001 From: Joel Chen Date: Wed, 11 Apr 2018 15:07:29 -0700 Subject: [PATCH] generate app with sample to show electrode server startup events --- .../app/templates/src/server/index.js | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/packages/generator-electrode/generators/app/templates/src/server/index.js b/packages/generator-electrode/generators/app/templates/src/server/index.js index 49fc69357..27fe4adc3 100644 --- a/packages/generator-electrode/generators/app/templates/src/server/index.js +++ b/packages/generator-electrode/generators/app/templates/src/server/index.js @@ -11,14 +11,40 @@ const support = require("electrode-archetype-react-app/support"); //<% if (isHapi) { %> const staticPathsDecor = require("electrode-static-paths"); -const startServer = config => require("electrode-server")(config, [staticPathsDecor()]); +const electrodeServer = require("electrode-server"); + +// +// sample to show electrode server startup events +// https://github.com/electrode-io/electrode-server#listener-function +// +function setupElectrodeServerEvents(emitter) { + emitter.on("config-composed", (data, next) => next()); + emitter.on("server-created", (data, next) => next()); + emitter.on("connection-set", (data, next) => next()); + emitter.on("plugins-sorted", (data, next) => next()); + emitter.on("plugins-registered", (data, next) => next()); + emitter.on("server-started", (data, next) => next()); + emitter.on("complete", (data, next) => next()); +} + +const startServer = config => { + const decor = staticPathsDecor(); + if (!config.listener) config.listener = setupElectrodeServerEvents; + return electrodeServer(config, [decor]); +}; + //<% } else if (isExpress) { %> const startServer = config => require("./express-server")(config); //<% } else { %> const startServer = config => require("./koa-server")(config); //<% } %> -support.load().then(() => { - const config = electrodeConfippet.config; - return startServer(config); -}); +module.exports = () => + support.load().then(() => { + const config = electrodeConfippet.config; + return startServer(config); + }); + +if (require.main === module) { + module.exports(); +}