@@ -23,8 +23,19 @@ patchLStat();
23
23
// Set by NodeJSProcessFactory
24
24
let projectDir = process . cwd ( ) ;
25
25
26
+ // Create server
27
+ const server = http . createServer ( serverOnRequestListener ) ;
28
+
29
+ // In Node.js 13+ this is the new default, however for earlier versions it is 120 seconds
30
+ server . setTimeout ( 0 ) ;
31
+
32
+ // If a connection drops we want as much information as possible
33
+ server . on ( 'clientError' , serverOnClientError ) ;
34
+
26
35
// Start server
27
- const server = http . createServer ( ( req , res ) => {
36
+ server . listen ( parseInt ( args . port ) , 'localhost' , serverOnListeningListener ) ;
37
+
38
+ function serverOnRequestListener ( req , res ) {
28
39
let bodyChunks = [ ] ;
29
40
req .
30
41
on ( 'data' , chunk => bodyChunks . push ( chunk ) ) .
@@ -158,12 +169,24 @@ const server = http.createServer((req, res) => {
158
169
respondWithError ( res , error ) ;
159
170
}
160
171
} ) ;
161
- } ) . listen ( parseInt ( args . port ) , 'localhost' , function ( ) {
172
+ }
173
+
174
+ function serverOnClientError ( error : Error , socket : stream . Duplex ) {
175
+ let errorString = error . toString ( ) ;
176
+ let httpResponseMessage = `HTTP/1.1 400 Bad Request\r
177
+ Content-Length: ${ Buffer . byteLength ( errorString , 'utf8' ) }
178
+ Content-Type: text/html\r
179
+ \r
180
+ ${ errorString } `;
181
+ socket . end ( httpResponseMessage ) ;
182
+ }
183
+
184
+ function serverOnListeningListener ( ) {
162
185
// Signal to HttpNodeHost which loopback IP address (IPv4 or IPv6) and port it should make its HTTP connections on
163
186
// and that we are ready to process invocations.
164
187
let info = server . address ( ) as AddressInfo ;
165
188
console . log ( `[Jering.Javascript.NodeJS: Listening on IP - ${ info . address } Port - ${ info . port } ]` ) ;
166
- } ) ;
189
+ }
167
190
168
191
function getTempIdentifier ( invocationRequest : InvocationRequest ) : string {
169
192
if ( invocationRequest . newCacheIdentifier == null ) {
0 commit comments