start.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. const path = require('path');
  3. module.exports = async (options = {}) => {
  4. if (!options.ignoreWarning) {
  5. console.warn('single process mode is still in experiment, please don\'t use it in production environment');
  6. }
  7. options.baseDir = options.baseDir || process.cwd();
  8. options.mode = 'single';
  9. // get agent from options.framework and package.egg.framework
  10. if (!options.framework) {
  11. try {
  12. options.framework = require(path.join(options.baseDir, 'package.json')).egg.framework;
  13. } catch (_) {
  14. // ignore
  15. }
  16. }
  17. let Agent;
  18. let Application;
  19. if (options.framework) {
  20. Agent = require(options.framework).Agent;
  21. Application = require(options.framework).Application;
  22. } else {
  23. Application = require('./application');
  24. Agent = require('./agent');
  25. }
  26. const agent = new Agent(Object.assign({}, options));
  27. await agent.ready();
  28. const application = new Application(Object.assign({}, options));
  29. application.agent = agent;
  30. agent.application = application;
  31. await application.ready();
  32. // emit egg-ready message in agent and application
  33. application.messenger.broadcast('egg-ready');
  34. return application;
  35. };