-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.js
42 lines (35 loc) · 1.15 KB
/
start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
const path = require('path');
module.exports = async (options = {}) => {
if (!options.ignoreWarning) {
console.warn('single process mode is still in experiment, please don\'t use it in production environment');
}
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;
};