@midwayjs/koa 3.20.5 → 3.20.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.
- package/dist/framework.js +5 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +18 -1
- package/package.json +6 -6
package/dist/framework.js
CHANGED
|
@@ -14,6 +14,7 @@ const koa = require("koa");
|
|
|
14
14
|
const onerror_1 = require("./onerror");
|
|
15
15
|
const qs = require("qs");
|
|
16
16
|
const querystring = require("querystring");
|
|
17
|
+
const utils_1 = require("./utils");
|
|
17
18
|
const COOKIES = Symbol('context#cookies');
|
|
18
19
|
class KoaControllerGenerator extends core_1.WebControllerGenerator {
|
|
19
20
|
constructor(app, webRouterService) {
|
|
@@ -219,7 +220,10 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
219
220
|
this.server.setTimeout(this.configurationOptions.serverTimeout);
|
|
220
221
|
}
|
|
221
222
|
// set port and listen server
|
|
222
|
-
|
|
223
|
+
let customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : this.configurationOptions.port;
|
|
224
|
+
if (customPort === 0) {
|
|
225
|
+
customPort = await (0, utils_1.getFreePort)();
|
|
226
|
+
}
|
|
223
227
|
if (customPort) {
|
|
224
228
|
new Promise(resolve => {
|
|
225
229
|
const args = [customPort];
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.escapeHtml = exports.tpl = exports.isProduction = exports.sendToWormhole = exports.accepts = exports.detectStatus = void 0;
|
|
3
|
+
exports.getFreePort = exports.escapeHtml = exports.tpl = exports.isProduction = exports.sendToWormhole = exports.accepts = exports.detectStatus = void 0;
|
|
4
|
+
const net_1 = require("net");
|
|
4
5
|
function detectStatus(err) {
|
|
5
6
|
// detect status
|
|
6
7
|
let status = err.status || 500;
|
|
@@ -153,4 +154,20 @@ function escapeHtml(string) {
|
|
|
153
154
|
return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
|
|
154
155
|
}
|
|
155
156
|
exports.escapeHtml = escapeHtml;
|
|
157
|
+
async function getFreePort() {
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
const server = (0, net_1.createServer)();
|
|
160
|
+
server.listen(0, () => {
|
|
161
|
+
try {
|
|
162
|
+
const port = server.address().port;
|
|
163
|
+
server.close();
|
|
164
|
+
resolve(port);
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
reject(err);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
exports.getFreePort = getFreePort;
|
|
156
173
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/koa",
|
|
3
|
-
"version": "3.20.
|
|
3
|
+
"version": "3.20.12",
|
|
4
4
|
"description": "Midway Web Framework for KOA",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@midwayjs/mock": "^3.20.
|
|
27
|
+
"@midwayjs/mock": "^3.20.11",
|
|
28
28
|
"@types/koa-router": "7.4.8",
|
|
29
29
|
"fs-extra": "11.3.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@koa/router": "^12.0.0",
|
|
33
33
|
"@midwayjs/cookies": "^1.3.0",
|
|
34
|
-
"@midwayjs/core": "^3.20.
|
|
35
|
-
"@midwayjs/session": "^3.20.
|
|
34
|
+
"@midwayjs/core": "^3.20.11",
|
|
35
|
+
"@midwayjs/session": "^3.20.11",
|
|
36
36
|
"@types/koa": "2.15.0",
|
|
37
37
|
"@types/qs": "6.9.18",
|
|
38
|
-
"koa": "2.16.
|
|
38
|
+
"koa": "2.16.2",
|
|
39
39
|
"koa-bodyparser": "4.4.1",
|
|
40
40
|
"qs": "6.14.0"
|
|
41
41
|
},
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=12"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "de297e0d18cbfd86b3043c4ad0c1a7c991415711"
|
|
51
51
|
}
|