add shared event bus to server api
This commit is contained in:
parent
f4ab41996a
commit
383a31d7a9
1 changed files with 7 additions and 0 deletions
7
app.js
7
app.js
|
|
@ -1,5 +1,6 @@
|
|||
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||
|
||||
// ensure each app gets a local version-specific copy, not shared
|
||||
function require_fresh(path) {
|
||||
const rpa = require.resolve(path);
|
||||
delete require.cache[rpa];
|
||||
|
|
@ -34,6 +35,10 @@ let util;
|
|||
let dir;
|
||||
let log;
|
||||
|
||||
const EventEmitter = require('events');
|
||||
class AppEmitter extends EventEmitter {}
|
||||
const events = new AppEmitter();
|
||||
|
||||
function init(mod) {
|
||||
startTime = time();
|
||||
lastmod = mod.util.lastmod;
|
||||
|
|
@ -202,11 +207,13 @@ function loadModule(mod, dir) {
|
|||
function initModule(mod, file, dir) {
|
||||
logger.log({module: file});
|
||||
require_fresh(file)({
|
||||
// express functions added here show up at "/api/" url root
|
||||
api: api,
|
||||
adm: {
|
||||
reload: prepareScripts,
|
||||
setver: (ver) => { oversion = ver }
|
||||
},
|
||||
events,
|
||||
const: {
|
||||
args: {},
|
||||
meta: mod.meta,
|
||||
|
|
|
|||
Loading…
Reference in a new issue