mirror of
https://github.com/eggjs/egg.git
synced 2024-12-04 07:14:30 +00:00
Since we're now successfully using this feature for a long time without obvious bugs/errors, there's no need for us to make it as an "experinment" feature and now it's come to ture. Ref: https://github.com/eggjs/egg/pull/3430
40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
const path = require('path');
|
|
|
|
module.exports = async (options = {}) => {
|
|
|
|
options.baseDir = options.baseDir || process.cwd();
|
|
options.mode = 'single';
|
|
|
|
// get agent from options.framework and package.egg.framework
|
|
if (!options.framework) {
|
|
try {
|
|
options.framework = require(path.join(options.baseDir, 'package.json')).egg.framework;
|
|
} catch (_) {
|
|
// ignore
|
|
}
|
|
}
|
|
let Agent;
|
|
let Application;
|
|
if (options.framework) {
|
|
Agent = require(options.framework).Agent;
|
|
Application = require(options.framework).Application;
|
|
} else {
|
|
Application = require('./application');
|
|
Agent = require('./agent');
|
|
}
|
|
|
|
const agent = new Agent(Object.assign({}, options));
|
|
await agent.ready();
|
|
const application = new Application(Object.assign({}, options));
|
|
application.agent = agent;
|
|
agent.application = application;
|
|
await application.ready();
|
|
|
|
// emit egg-ready message in agent and application
|
|
application.messenger.broadcast('egg-ready');
|
|
|
|
return application;
|
|
};
|