File tree Expand file tree Collapse file tree 2 files changed +13
-8
lines changed
Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ export class HttpServer {
7575 private _protocol : HttpProtocol ;
7676 private _address : AddressInfo ;
7777 private requestListener : RequestListener ;
78- private server : http . Server | https . Server ;
78+ readonly server : http . Server | https . Server ;
7979 private serverOptions ?: HttpServerOptions ;
8080
8181 /**
@@ -91,12 +91,6 @@ export class HttpServer {
9191 this . _port = serverOptions ? serverOptions . port || 0 : 0 ;
9292 this . _host = serverOptions ? serverOptions . host : undefined ;
9393 this . _protocol = serverOptions ? serverOptions . protocol || 'http' : 'http' ;
94- }
95-
96- /**
97- * Starts the HTTP / HTTPS server
98- */
99- public async start ( ) {
10094 if ( this . _protocol === 'https' ) {
10195 this . server = https . createServer (
10296 this . serverOptions as https . ServerOptions ,
@@ -105,6 +99,12 @@ export class HttpServer {
10599 } else {
106100 this . server = http . createServer ( this . requestListener ) ;
107101 }
102+ }
103+
104+ /**
105+ * Starts the HTTP / HTTPS server
106+ */
107+ public async start ( ) {
108108 this . server . listen ( this . _port , this . _host ) ;
109109 await pEvent ( this . server , 'listening' ) ;
110110 this . _listening = true ;
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import {
1212 givenHttpServerConfig ,
1313} from '@loopback/testlab' ;
1414import * as makeRequest from 'request-promise-native' ;
15- import { IncomingMessage , ServerResponse } from 'http' ;
15+ import { IncomingMessage , ServerResponse , Server } from 'http' ;
1616import * as path from 'path' ;
1717import * as fs from 'fs' ;
1818
@@ -121,6 +121,11 @@ describe('HttpServer (integration)', () => {
121121 . which . is . an . Object ( ) ;
122122 } ) ;
123123
124+ it ( 'exports server before start' , async ( ) => {
125+ server = new HttpServer ( dummyRequestHandler ) ;
126+ expect ( server . server ) . to . be . instanceOf ( Server ) ;
127+ } ) ;
128+
124129 it ( 'resets address when server is stopped' , async ( ) => {
125130 server = new HttpServer ( dummyRequestHandler ) ;
126131 await server . start ( ) ;
You can’t perform that action at this time.
0 commit comments