@@ -37,6 +37,18 @@ module.exports = async function(api, info = {}) {
3737
3838 app . server = server ;
3939
40+ const portfinder = require ( 'portfinder' ) ;
41+ const startPort = parseInt ( process . env . PORT || apiContext . port || port || 3000 ) ;
42+ const _port = await portfinder . getPortPromise ( {
43+ port : startPort , // minimum port
44+ stopPort : startPort + 300 , // maximum port
45+ } ) ;
46+ const _host = process . env . HOST || apiContext . host || host || '0.0.0.0' ;
47+
48+ // 基本信息
49+ const serverInfo = { protocol, host : _host , port : _port } ;
50+ app . server . info = serverInfo ;
51+
4052 if ( entries . length > 0 ) {
4153 await entries . reduce ( ( chain , entry ) => {
4254 const runApp = require ( entry ) ; // app.js
@@ -49,15 +61,7 @@ module.exports = async function(api, info = {}) {
4961 await runApp ( app ) ;
5062 }
5163
52- const portfinder = require ( 'portfinder' ) ;
53- const startPort = parseInt ( process . env . PORT || apiContext . port || port || 3000 ) ;
54- const _port = await portfinder . getPortPromise ( {
55- port : startPort , // minimum port
56- stopPort : startPort + 300 , // maximum port
57- } ) ;
58- const _host = process . env . HOST || apiContext . host || host || '0.0.0.0' ;
59-
60- const ps = [ listen ( app , { protocol, host : _host , port : _port } ) ] ;
64+ const ps = [ listen ( app , serverInfo ) ] ;
6165 return Promise . all ( ps ) . then ( ress => {
6266 const res = { ...ress [ 0 ] } ;
6367 return res ; // 只返回第一个配置
0 commit comments