UNPKG

hapiboot

Version:
40 lines (35 loc) 869 B
"use strict"; /** * Hapi Modular Boot */ class Boot{ constructor( hapi, config ){ this.config = config; this.hapi = hapi; } /** * Booting modules */ boot(){ let root = this.config.api.root; let modules = this.config.modules; for(let i = 0; i < modules.length; i++){ let module = modules[i]; try{ this.loadModuleByPath(process.cwd()+"/"+root+"/"+module); this.hapi.log(['debug'], "Module "+module+" loaded"); }catch(e){ this.hapi.log(['debug', 'error'], "FAILED load "+module); } } } /** * Load module by given path * @param {String} path */ loadModuleByPath(path){ let module = require(path); this.hapi.route(module); } } module.exports = Boot;