Skip to content
Snippets Groups Projects
index.js 601 B
Newer Older
  • Learn to ignore specific revisions
  • James Long's avatar
    James Long committed
    let bundle = require('./app/bundle.api.js');
    
    let injected = require('./injected');
    
    James Long's avatar
    James Long committed
    let methods = require('./methods');
    let utils = require('./utils');
    let actualApp;
    
    
    async function init(config = {}) {
    
    James Long's avatar
    James Long committed
      if (actualApp) {
        return;
      }
    
      global.fetch = require('node-fetch');
    
    
      await bundle.init(config);
    
    James Long's avatar
    James Long committed
      actualApp = bundle.lib;
    
      injected.send = bundle.lib.send;
      return bundle.lib;
    }
    
    async function shutdown() {
      if (actualApp) {
        await actualApp.send('close-budget');
        actualApp = null;
      }
    }
    
    module.exports = {
      init,
      shutdown,
      utils,
      internal: bundle.lib,
    
    James Long's avatar
    James Long committed
    };