@@ -31,6 +31,12 @@ module.exports = async function(api, info = {}) {
3131 server = createServer ( app , { protocol, isOpenHttp2 : http2 } ) ;
3232 }
3333
34+ if ( ! server ) {
35+ throw new Error ( 'server is null' ) ;
36+ }
37+
38+ app . server = server ;
39+
3440 if ( entries . length > 0 ) {
3541 await entries . reduce ( ( chain , entry ) => {
3642 const runApp = require ( entry ) ; // app.js
@@ -51,7 +57,7 @@ module.exports = async function(api, info = {}) {
5157 } ) ;
5258 const _host = process . env . HOST || apiContext . host || host || '0.0.0.0' ;
5359
54- const ps = [ listen ( server , { protocol, host : _host , port : _port } ) ] ;
60+ const ps = [ listen ( app , { protocol, host : _host , port : _port } ) ] ;
5561 return Promise . all ( ps ) . then ( ress => {
5662 const res = { ...ress [ 0 ] } ;
5763 return res ; // 只返回第一个配置
@@ -89,11 +95,10 @@ function createServer(app, { protocol, isOpenHttp2 }, options) {
8995 throw new Error ( `Not Support protocol: ${ protocol } !` ) ;
9096 }
9197
92- app . server = server ;
9398 return server ;
9499}
95100
96- function listen ( server , { protocol, host, port } ) {
101+ function listen ( app , { protocol, host, port } ) {
97102 return new Promise ( ( resolve , reject ) => {
98103 const errCb = err => {
99104 if ( err ) {
@@ -106,8 +111,8 @@ function listen(server, { protocol, host, port }) {
106111 }
107112 } ;
108113
109- if ( server ) {
110- server . listen ( port , errCb ) ;
114+ if ( app ) {
115+ app . listen ( app . server , port , errCb ) ;
111116 } else {
112117 reject ( new Error ( `Not Support protocol: ${ protocol } !` ) ) ;
113118 }
0 commit comments