egg/lib/start.js
William.Tung 322b35bd97
chore: remove SingleProcess warnings (#5223)
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
2023-06-24 01:08:08 +08:00

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;
};