Skip to content

Commit

Permalink
generate app with sample to show electrode server startup events
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Apr 11, 2018
1 parent 8bdb189 commit 38b39ce
Showing 1 changed file with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 38b39ce

Please sign in to comment.