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 {
75
75
private _protocol : HttpProtocol ;
76
76
private _address : AddressInfo ;
77
77
private requestListener : RequestListener ;
78
- private server : http . Server | https . Server ;
78
+ readonly server : http . Server | https . Server ;
79
79
private serverOptions ?: HttpServerOptions ;
80
80
81
81
/**
@@ -91,12 +91,6 @@ export class HttpServer {
91
91
this . _port = serverOptions ? serverOptions . port || 0 : 0 ;
92
92
this . _host = serverOptions ? serverOptions . host : undefined ;
93
93
this . _protocol = serverOptions ? serverOptions . protocol || 'http' : 'http' ;
94
- }
95
-
96
- /**
97
- * Starts the HTTP / HTTPS server
98
- */
99
- public async start ( ) {
100
94
if ( this . _protocol === 'https' ) {
101
95
this . server = https . createServer (
102
96
this . serverOptions as https . ServerOptions ,
@@ -105,6 +99,12 @@ export class HttpServer {
105
99
} else {
106
100
this . server = http . createServer ( this . requestListener ) ;
107
101
}
102
+ }
103
+
104
+ /**
105
+ * Starts the HTTP / HTTPS server
106
+ */
107
+ public async start ( ) {
108
108
this . server . listen ( this . _port , this . _host ) ;
109
109
await pEvent ( this . server , 'listening' ) ;
110
110
this . _listening = true ;
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import {
12
12
givenHttpServerConfig ,
13
13
} from '@loopback/testlab' ;
14
14
import * as makeRequest from 'request-promise-native' ;
15
- import { IncomingMessage , ServerResponse } from 'http' ;
15
+ import { IncomingMessage , ServerResponse , Server } from 'http' ;
16
16
import * as path from 'path' ;
17
17
import * as fs from 'fs' ;
18
18
@@ -121,6 +121,11 @@ describe('HttpServer (integration)', () => {
121
121
. which . is . an . Object ( ) ;
122
122
} ) ;
123
123
124
+ it ( 'exports server before start' , async ( ) => {
125
+ server = new HttpServer ( dummyRequestHandler ) ;
126
+ expect ( server . server ) . to . be . instanceOf ( Server ) ;
127
+ } ) ;
128
+
124
129
it ( 'resets address when server is stopped' , async ( ) => {
125
130
server = new HttpServer ( dummyRequestHandler ) ;
126
131
await server . start ( ) ;
You can’t perform that action at this time.
0 commit comments