@midwayjs/web 3.0.0-alpha.9 → 3.0.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,122 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwayWebSingleProcessFramework = void 0;
4
- const core_1 = require("@midwayjs/core");
5
- const path_1 = require("path");
6
- const koa_1 = require("@midwayjs/koa");
7
- class MidwayWebSingleProcessFramework {
8
- getApplication() {
9
- return this.app;
10
- }
11
- getFrameworkType() {
12
- return core_1.MidwayFrameworkType.WEB;
13
- }
14
- async run() {
15
- // trigger server didReady
16
- this.app.messenger.emit('egg-ready');
17
- if (this.configurationOptions.port) {
18
- new Promise(resolve => {
19
- const args = [this.configurationOptions.port];
20
- if (this.configurationOptions.hostname) {
21
- args.push(this.configurationOptions.hostname);
22
- }
23
- args.push(() => {
24
- resolve();
25
- });
26
- this.server.listen(...args);
27
- });
28
- }
29
- }
30
- configure(options = {}) {
31
- this.configurationOptions = options;
32
- return this;
33
- }
34
- getApplicationContext() {
35
- return this.app.getApplicationContext();
36
- }
37
- getConfiguration(key) {
38
- return this.app.getConfig(key);
39
- }
40
- getCurrentEnvironment() {
41
- return this.app.getEnv();
42
- }
43
- async initialize(options) {
44
- const opts = {
45
- baseDir: options.appDir,
46
- framework: path_1.resolve(__dirname, '../application'),
47
- plugins: this.configurationOptions.plugins,
48
- mode: 'single',
49
- isTsMode: this.isTsMode || true,
50
- applicationContext: options.applicationContext,
51
- midwaySingleton: true,
52
- };
53
- const Agent = require(opts.framework).Agent;
54
- const Application = require(opts.framework).Application;
55
- const agent = (this.agent = new Agent(Object.assign({}, opts)));
56
- await agent.ready();
57
- const application = (this.app = new Application(Object.assign({}, opts)));
58
- application.agent = agent;
59
- agent.application = application;
60
- // https config
61
- if (this.configurationOptions.key && this.configurationOptions.cert) {
62
- this.configurationOptions.key = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.key);
63
- this.configurationOptions.cert = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.cert);
64
- this.configurationOptions.ca = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.ca);
65
- this.server = require('https').createServer(this.configurationOptions, this.app.callback());
66
- }
67
- else {
68
- this.server = require('http').createServer(this.app.callback());
69
- }
70
- if (options.isMainFramework === undefined) {
71
- await this.loadExtension();
72
- }
73
- }
74
- async loadExtension() {
75
- // 延迟加载 egg 的 load 方法
76
- await this.app.loader.loadOrigin();
77
- await this.app.ready();
78
- // emit egg-ready message in agent and application
79
- this.app.messenger.broadcast('egg-ready', undefined);
80
- // emit `server` event in app
81
- this.app.emit('server', this.server);
82
- // register httpServer to applicationContext
83
- this.getApplicationContext().registerObject(core_1.HTTP_SERVER_KEY, this.server);
84
- }
85
- async stop() {
86
- await new Promise(resolve => {
87
- this.server.close(resolve);
88
- });
89
- await this.app.close();
90
- await this.agent.close();
91
- }
92
- getBaseDir() {
93
- return this.app.getBaseDir();
94
- }
95
- getAppDir() {
96
- return this.app.getAppDir();
97
- }
98
- getLogger(name) {
99
- return this.app.getLogger(name);
100
- }
101
- getCoreLogger() {
102
- return this.app.coreLogger;
103
- }
104
- getProjectName() {
105
- return this.app.getProjectName();
106
- }
107
- createLogger(name, options) {
108
- return this.app.createLogger(name, options);
109
- }
110
- getServer() {
111
- return this.server;
112
- }
113
- getFrameworkName() {
114
- return 'midway:web';
115
- }
116
- getDefaultContextLoggerClass() {
117
- return koa_1.MidwayKoaContextLogger;
118
- }
119
- loadLifeCycles() { }
120
- }
121
- exports.MidwayWebSingleProcessFramework = MidwayWebSingleProcessFramework;
122
- //# sourceMappingURL=singleProcess.js.map
package/dist/starter.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { BootstrapStarter } from '@midwayjs/bootstrap';
2
- interface WebStarterOptions {
3
- isWorker: boolean;
4
- applicationContext?: any;
5
- }
6
- export declare class WebBootstrapStarter extends BootstrapStarter {
7
- options: WebStarterOptions;
8
- constructor(options: WebStarterOptions);
9
- init(): Promise<void>;
10
- }
11
- export {};
12
- //# sourceMappingURL=starter.d.ts.map
package/dist/starter.js DELETED
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebBootstrapStarter = void 0;
4
- const bootstrap_1 = require("@midwayjs/bootstrap");
5
- class WebBootstrapStarter extends bootstrap_1.BootstrapStarter {
6
- constructor(options) {
7
- super();
8
- this.options = options;
9
- }
10
- async init() {
11
- this.appDir = this.globalOptions.appDir || process.cwd();
12
- this.baseDir = this.getBaseDir();
13
- await this.getFirstActions('initialize', {
14
- ...this.globalOptions,
15
- baseDir: this.baseDir,
16
- appDir: this.appDir,
17
- isMainFramework: this.options.isWorker ? true : undefined,
18
- applicationContext: this.options.applicationContext,
19
- });
20
- }
21
- }
22
- exports.WebBootstrapStarter = WebBootstrapStarter;
23
- //# sourceMappingURL=starter.js.map