Os projetos de fim de semana não são ótimos !?
Depois de muito barulho, esse é o padrão que escolhi para iniciar os
aplicativos. Alguns dos npms são privados, mas você entendeu.
TODO: veja https://github.com/spumko/hapi/blob/master/docs/Reference.md#hapipack
var config = require("./configs/" + process.env.NODE_ENV),
figure = require("droppe-figure"),
bunyan = require("bunyan"),
applicationName,
logger;
applicationName = config.get("applicationName");
logger = bunyan.createLogger({name: applicationName});
// Get options from the confiuration service
figure.get("/" + applicationName + "/" + process.env).then(function (options) {
var hapi = require('hapi'),
server;
// Merge local config with service config
Object.keys(options).forEach(function (key) {
config.set(key, options[key]);
});
// Make hapi
server = new hapi.Server(
config.get("hostname"),
config.get("port"),
config.get("application")
);
logger.info("Starting the application w/", config.get());
// start the server
server.start(function (error) {
var loader;
if (error) {
logger.warn("Failed to start application at w/", error);
return;
}
loader = require("node-glob-loader");
server.app.logger = logger;
// Load application routes
loader.load(["./application/routes/*", "./application/routes/**/*"], function (exports) {
exports(server, config);
}).then(function () {
logger.warn("Started application at ", server.info.uri);
}).done();
});
}).fail(function (error) {
logger.warn("Failed to start application at w/", error);
}).done();