@@ -34,14 +34,14 @@ export type Transport = {
3434
3535export class HttpServer {
3636 private _server : http . Server ;
37- private _urlPrefix : string ;
37+ private _urlPrefixPrecise : string = '' ;
38+ private _urlPrefixHumanReadable : string = '' ;
3839 private _port : number = 0 ;
3940 private _started = false ;
4041 private _routes : { prefix ?: string , exact ?: string , handler : ServerRouteHandler } [ ] = [ ] ;
4142 private _wsGuid : string | undefined ;
4243
43- constructor ( address : string = '' ) {
44- this . _urlPrefix = address ;
44+ constructor ( ) {
4545 this . _server = createHttpServer ( this . _onRequest . bind ( this ) ) ;
4646 }
4747
@@ -102,7 +102,7 @@ export class HttpServer {
102102 return this . _wsGuid ;
103103 }
104104
105- async start ( options : { port ?: number , preferredPort ?: number , host ?: string } = { } ) : Promise < string > {
105+ async start ( options : { port ?: number , preferredPort ?: number , host ?: string } = { } ) : Promise < void > {
106106 assert ( ! this . _started , 'server already started' ) ;
107107 this . _started = true ;
108108
@@ -121,24 +121,23 @@ export class HttpServer {
121121
122122 const address = this . _server . address ( ) ;
123123 assert ( address , 'Could not bind server socket' ) ;
124- if ( ! this . _urlPrefix ) {
125- if ( typeof address === 'string' ) {
126- this . _urlPrefix = address ;
127- } else {
128- this . _port = address . port ;
129- const resolvedHost = address . family === 'IPv4' ? address . address : `[${ address . address } ]` ;
130- this . _urlPrefix = `http://${ resolvedHost } :${ address . port } ` ;
131- }
124+ if ( typeof address === 'string' ) {
125+ this . _urlPrefixPrecise = address ;
126+ this . _urlPrefixHumanReadable = address ;
127+ } else {
128+ this . _port = address . port ;
129+ const resolvedHost = address . family === 'IPv4' ? address . address : `[${ address . address } ]` ;
130+ this . _urlPrefixPrecise = `http://${ resolvedHost } :${ address . port } ` ;
131+ this . _urlPrefixHumanReadable = `http:// ${ host } : ${ address . port } ` ;
132132 }
133- return this . _urlPrefix ;
134133 }
135134
136135 async stop ( ) {
137136 await new Promise ( cb => this . _server ! . close ( cb ) ) ;
138137 }
139138
140- urlPrefix ( ) : string {
141- return this . _urlPrefix ;
139+ urlPrefix ( purpose : 'human-readable' | 'precise' ) : string {
140+ return purpose === 'human-readable' ? this . _urlPrefixHumanReadable : this . _urlPrefixPrecise ;
142141 }
143142
144143 serveFile ( request : http . IncomingMessage , response : http . ServerResponse , absoluteFilePath : string , headers ?: { [ name : string ] : string } ) : boolean {
0 commit comments