@@ -60,6 +60,26 @@ const argv = (() => {
60
60
default : defaultPort ,
61
61
help : `Changes the port. (default: ${ defaultPort } )` ,
62
62
} ) ;
63
+ parser . add_argument ( '--public_hostname' , {
64
+ nargs : '?' ,
65
+ type : 'str' ,
66
+ help : 'The hostname that clients can use to access the client; useful when running in a container.' ,
67
+ } ) ;
68
+ parser . add_argument ( '--public_port' , {
69
+ nargs : '?' ,
70
+ type : 'int' ,
71
+ help : 'The port that clients can use to access the client; useful when running in a container.' ,
72
+ } ) ;
73
+ parser . add_argument ( '--public_tls' , {
74
+ action : 'store_true' ,
75
+ default : false ,
76
+ help : 'Whether the public address should use TLS; useful when running in a container.' ,
77
+ } ) ;
78
+ parser . add_argument ( '--use_subdomains' , {
79
+ action : 'store_true' ,
80
+ default : false ,
81
+ help : 'Whether the server links should use subdomains off of the public address.' ,
82
+ } ) ;
63
83
parser . add_argument ( '--internal_backend' , {
64
84
nargs : '?' ,
65
85
type : 'str' ,
@@ -89,6 +109,9 @@ const argv = (() => {
89
109
} ) ( ) ;
90
110
91
111
const hostAddress = argv . host === '0.0.0.0' ? localhost : argv . host ;
112
+ const publicHostAddress = argv . public_hostname ? argv . public_hostname : hostAddress ;
113
+ const publicPort = argv . public_port ? argv . public_port : argv . port ;
114
+ const publicProtocol = argv . public_tls ? 'https' : 'http' ;
92
115
93
116
const getProxyTarget = ( backend : string ) =>
94
117
argv . internal_backend && backend . includes ( localhost ) ? argv . internal_backend : backend ;
@@ -132,9 +155,15 @@ const koa = new Koa();
132
155
const { host, port } = argv ;
133
156
const server = koa . listen ( port , host ) ;
134
157
server . on ( 'error' , ( err ) => handleServerError ( err , argv . debug ) ) ;
135
- server . on ( 'listening' , ( ) =>
136
- console . log ( '🌐' , chalk . dim ( 'Ready' , arrow ) , chalk . white ( `http://${ hostAddress } :${ port } /` ) ) ,
137
- ) ;
158
+ server . on ( 'listening' , ( ) => {
159
+ const hostport = port == 80 ? hostAddress : `${ hostAddress } :${ port } ` ;
160
+ console . log ( '🌐' , chalk . dim ( 'Ready' , arrow ) , chalk . white ( `http://${ hostport } /` ) ) ;
161
+ if ( ( publicHostAddress != hostAddress ) || ( publicPort != argv . port ) ) {
162
+ const protocolPort = argv . public_tls ? 443 : 80 ;
163
+ const public_hostport = publicPort == protocolPort ? publicHostAddress : `${ publicHostAddress } :${ publicPort } ` ;
164
+ console . log ( '🌐' , chalk . dim ( 'Public' , arrow ) , chalk . white ( `${ publicProtocol } ://${ public_hostport } /` ) ) ;
165
+ }
166
+ } ) ;
138
167
139
168
// Get system path for public files dir
140
169
const indexFile = 'index.ejs' ;
@@ -158,7 +187,8 @@ koa.use(async (ctx, next) => {
158
187
koa . use ( async ( context , next ) => {
159
188
if ( [ '/' , 'index.html' ] . includes ( context . path ) ) {
160
189
const communityPages = getCommunityPages ( ) ;
161
- let serverList = await getServerListConfig ( __dirname , hostAddress , port , argv . server_list ) ;
190
+ const useSubdomains = publicHostAddress == 'localhost' || argv . use_subdomains ;
191
+ let serverList = await getServerListConfig ( __dirname , publicProtocol , publicHostAddress , publicPort , useSubdomains , argv . server_list ) ;
162
192
await context . render ( indexFile , { serverList, communityPages } ) ;
163
193
}
164
194
0 commit comments