@midwayjs/express 3.20.4 → 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 +4 -1
- package/dist/util.d.ts +1 -0
- package/dist/util.js +18 -1
- package/package.json +5 -5
package/dist/framework.js
CHANGED
|
@@ -141,7 +141,10 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
141
141
|
}
|
|
142
142
|
// register httpServer to applicationContext
|
|
143
143
|
this.applicationContext.registerObject(core_1.HTTP_SERVER_KEY, this.server);
|
|
144
|
-
|
|
144
|
+
let customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : this.configurationOptions.port;
|
|
145
|
+
if (customPort === 0) {
|
|
146
|
+
customPort = await (0, util_2.getFreePort)();
|
|
147
|
+
}
|
|
145
148
|
if (customPort) {
|
|
146
149
|
new Promise(resolve => {
|
|
147
150
|
const args = [customPort];
|
package/dist/util.d.ts
CHANGED
package/dist/util.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendData = void 0;
|
|
3
|
+
exports.getFreePort = exports.sendData = void 0;
|
|
4
|
+
const net_1 = require("net");
|
|
4
5
|
function sendData(res, data) {
|
|
5
6
|
if (typeof data === 'number') {
|
|
6
7
|
res.status(res.statusCode).send('' + data);
|
|
@@ -10,4 +11,20 @@ function sendData(res, data) {
|
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
exports.sendData = sendData;
|
|
14
|
+
async function getFreePort() {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const server = (0, net_1.createServer)();
|
|
17
|
+
server.listen(0, () => {
|
|
18
|
+
try {
|
|
19
|
+
const port = server.address().port;
|
|
20
|
+
server.close();
|
|
21
|
+
resolve(port);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
reject(err);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.getFreePort = getFreePort;
|
|
13
30
|
//# sourceMappingURL=util.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/express",
|
|
3
|
-
"version": "3.20.
|
|
3
|
+
"version": "3.20.12",
|
|
4
4
|
"description": "Midway Web Framework for Express",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@midwayjs/mock": "^3.20.
|
|
27
|
+
"@midwayjs/mock": "^3.20.11",
|
|
28
28
|
"@types/body-parser": "1.19.5",
|
|
29
29
|
"@types/express": "4.17.21",
|
|
30
30
|
"fs-extra": "11.3.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@midwayjs/core": "^3.20.
|
|
34
|
-
"@midwayjs/express-session": "^3.20.
|
|
33
|
+
"@midwayjs/core": "^3.20.11",
|
|
34
|
+
"@midwayjs/express-session": "^3.20.11",
|
|
35
35
|
"body-parser": "1.20.3",
|
|
36
36
|
"cookie-parser": "^1.4.6",
|
|
37
37
|
"express": "4.21.2"
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=12"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "de297e0d18cbfd86b3043c4ad0c1a7c991415711"
|
|
48
48
|
}
|