@midwayjs/web 3.20.11 → 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/web.js +20 -1
- package/package.json +2 -2
package/dist/framework/web.js
CHANGED
|
@@ -15,6 +15,7 @@ const router_1 = require("@eggjs/router");
|
|
|
15
15
|
const logger_1 = require("@midwayjs/logger");
|
|
16
16
|
const path_1 = require("path");
|
|
17
17
|
const util_1 = require("util");
|
|
18
|
+
const net_1 = require("net");
|
|
18
19
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
19
20
|
class EggControllerGenerator extends core_1.WebControllerGenerator {
|
|
20
21
|
constructor(app, webRouterService) {
|
|
@@ -205,7 +206,10 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
205
206
|
this.getApplicationContext().registerObject(core_1.HTTP_SERVER_KEY, this.server);
|
|
206
207
|
const eggConfig = this.configService.getConfiguration('egg');
|
|
207
208
|
if (!this.isClusterMode && eggConfig) {
|
|
208
|
-
|
|
209
|
+
let customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : eggConfig.port;
|
|
210
|
+
if (customPort === 0) {
|
|
211
|
+
customPort = await getFreePort();
|
|
212
|
+
}
|
|
209
213
|
if (customPort) {
|
|
210
214
|
new Promise(resolve => {
|
|
211
215
|
const args = [customPort];
|
|
@@ -265,4 +269,19 @@ MidwayWebFramework = __decorate([
|
|
|
265
269
|
(0, core_1.Framework)()
|
|
266
270
|
], MidwayWebFramework);
|
|
267
271
|
exports.MidwayWebFramework = MidwayWebFramework;
|
|
272
|
+
async function getFreePort() {
|
|
273
|
+
return new Promise((resolve, reject) => {
|
|
274
|
+
const server = (0, net_1.createServer)();
|
|
275
|
+
server.listen(0, () => {
|
|
276
|
+
try {
|
|
277
|
+
const port = server.address().port;
|
|
278
|
+
server.close();
|
|
279
|
+
resolve(port);
|
|
280
|
+
}
|
|
281
|
+
catch (err) {
|
|
282
|
+
reject(err);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
268
287
|
//# sourceMappingURL=web.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/web",
|
|
3
|
-
"version": "3.20.
|
|
3
|
+
"version": "3.20.12",
|
|
4
4
|
"description": "Midway Web Framework for Egg.js",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=12"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "de297e0d18cbfd86b3043c4ad0c1a7c991415711"
|
|
64
64
|
}
|