@midwayjs/koa 3.20.12 → 3.20.15
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.
- package/dist/framework.js +16 -11
- package/dist/interface.d.ts +13 -0
- package/package.json +3 -2
- package/LICENSE +0 -21
package/dist/framework.js
CHANGED
|
@@ -183,7 +183,6 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
183
183
|
return mwIns.resolve();
|
|
184
184
|
}
|
|
185
185
|
async run() {
|
|
186
|
-
var _a;
|
|
187
186
|
// load controller
|
|
188
187
|
await this.loadMidwayController();
|
|
189
188
|
// restore use method
|
|
@@ -219,22 +218,27 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
219
218
|
if (core_1.Types.isNumber(this.configurationOptions.serverTimeout)) {
|
|
220
219
|
this.server.setTimeout(this.configurationOptions.serverTimeout);
|
|
221
220
|
}
|
|
221
|
+
this.configurationOptions.listenOptions = {
|
|
222
|
+
port: this.configurationOptions.port,
|
|
223
|
+
host: this.configurationOptions.hostname,
|
|
224
|
+
...this.configurationOptions.listenOptions,
|
|
225
|
+
};
|
|
222
226
|
// set port and listen server
|
|
223
|
-
let customPort =
|
|
224
|
-
|
|
227
|
+
let customPort = process.env.MIDWAY_HTTP_PORT ||
|
|
228
|
+
this.configurationOptions.listenOptions.port;
|
|
229
|
+
if (customPort === 0 || customPort === '0') {
|
|
225
230
|
customPort = await (0, utils_1.getFreePort)();
|
|
231
|
+
this.logger.info(`Midway koa is listening on port ${customPort} (auto assigned)`);
|
|
226
232
|
}
|
|
227
|
-
|
|
233
|
+
this.configurationOptions.listenOptions.port = Number(customPort);
|
|
234
|
+
if (this.configurationOptions.listenOptions.port) {
|
|
228
235
|
new Promise(resolve => {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
args.push(this.configurationOptions.hostname);
|
|
232
|
-
}
|
|
233
|
-
args.push(() => {
|
|
236
|
+
// 使用 ListenOptions 对象启动服务器
|
|
237
|
+
this.server.listen(this.configurationOptions.listenOptions, () => {
|
|
234
238
|
resolve();
|
|
235
239
|
});
|
|
236
|
-
|
|
237
|
-
process.env.MIDWAY_HTTP_PORT = String(
|
|
240
|
+
// 设置环境变量
|
|
241
|
+
process.env.MIDWAY_HTTP_PORT = String(this.configurationOptions.listenOptions.port);
|
|
238
242
|
});
|
|
239
243
|
}
|
|
240
244
|
}
|
|
@@ -242,6 +246,7 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
242
246
|
if (this.server) {
|
|
243
247
|
new Promise(resolve => {
|
|
244
248
|
this.server.close(resolve);
|
|
249
|
+
process.env.MIDWAY_HTTP_PORT = '';
|
|
245
250
|
});
|
|
246
251
|
}
|
|
247
252
|
}
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
3
4
|
import { IConfigurationOptions, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
|
|
4
5
|
import * as koa from 'koa';
|
|
5
6
|
import { Context as KoaContext, DefaultState, Middleware, Next } from 'koa';
|
|
6
7
|
import { RouterParamValue } from '@midwayjs/core';
|
|
7
8
|
import * as qs from 'qs';
|
|
9
|
+
import { ListenOptions } from 'net';
|
|
8
10
|
export interface State extends DefaultState {
|
|
9
11
|
}
|
|
10
12
|
export type IMidwayKoaContext = IMidwayContext<KoaContext>;
|
|
@@ -15,6 +17,10 @@ export type IMidwayKoaApplication = IMidwayApplication<IMidwayKoaContext, koa<St
|
|
|
15
17
|
* @param middlewareId
|
|
16
18
|
*/
|
|
17
19
|
generateMiddleware(middlewareId: any): Promise<Middleware<State, IMidwayKoaContext>>;
|
|
20
|
+
/**
|
|
21
|
+
* Get the port that the application is listening on
|
|
22
|
+
*/
|
|
23
|
+
getPort(): string;
|
|
18
24
|
}>;
|
|
19
25
|
/**
|
|
20
26
|
* @deprecated use NextFunction definition
|
|
@@ -86,7 +92,14 @@ export interface IMidwayKoaConfigurationOptions extends IConfigurationOptions {
|
|
|
86
92
|
* qs options
|
|
87
93
|
*/
|
|
88
94
|
queryParseOptions?: qs.IParseOptions;
|
|
95
|
+
/**
|
|
96
|
+
* https/https/http2 server options
|
|
97
|
+
*/
|
|
89
98
|
serverOptions?: Record<string, any>;
|
|
99
|
+
/**
|
|
100
|
+
* listen options
|
|
101
|
+
*/
|
|
102
|
+
listenOptions?: ListenOptions;
|
|
90
103
|
}
|
|
91
104
|
export type MiddlewareParamArray = Array<Middleware<DefaultState, IMidwayKoaContext>>;
|
|
92
105
|
export interface IWebMiddleware {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/koa",
|
|
3
|
-
"version": "3.20.
|
|
3
|
+
"version": "3.20.15",
|
|
4
4
|
"description": "Midway Web Framework for KOA",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@midwayjs/mock": "^3.20.11",
|
|
28
28
|
"@types/koa-router": "7.4.8",
|
|
29
|
+
"axios": "1.8.4",
|
|
29
30
|
"fs-extra": "11.3.0"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
@@ -47,5 +48,5 @@
|
|
|
47
48
|
"engines": {
|
|
48
49
|
"node": ">=12"
|
|
49
50
|
},
|
|
50
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "a603d2348d6141f8f723901498f03a162a037708"
|
|
51
52
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2013 - Now midwayjs
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|