File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,28 +32,33 @@ function fastbootExpressMiddleware(distPath, options) {
3232 . then ( success , failure ) ;
3333
3434 function success ( result ) {
35- result . html ( )
36- . then ( html => {
37- let headers = result . headers ;
38- let statusMessage = result . error ? 'NOT OK ' : 'OK ' ;
39-
40- for ( var pair of headers . entries ( ) ) {
41- res . set ( pair [ 0 ] , pair [ 1 ] ) ;
42- }
43-
44- if ( result . error ) {
45- log ( "RESILIENT MODE CAUGHT:" , result . error . stack ) ;
46- next ( result . error ) ;
47- }
48-
49- log ( result . statusCode , statusMessage + path ) ;
50- res . status ( result . statusCode ) ;
51- res . send ( html ) ;
52- } )
53- . catch ( error => {
54- res . status ( 500 ) ;
55- next ( error ) ;
56- } ) ;
35+ result . chunks ( )
36+ . then ( chunks => {
37+ let headers = result . headers ;
38+ let statusMessage = result . error ? 'NOT OK ' : 'OK ' ;
39+
40+ for ( var pair of headers . entries ( ) ) {
41+ res . set ( pair [ 0 ] , pair [ 1 ] ) ;
42+ }
43+
44+ if ( result . error ) {
45+ log ( "RESILIENT MODE CAUGHT:" , result . error . stack ) ;
46+ next ( result . error ) ;
47+ }
48+
49+ log ( result . statusCode , statusMessage + path ) ;
50+ res . status ( result . statusCode ) ;
51+ if ( result . error ) {
52+ res . send ( chunks [ 0 ] ) ;
53+ } else {
54+ chunks . forEach ( chunk => res . write ( chunk ) ) ;
55+ res . end ( ) ;
56+ }
57+ } )
58+ . catch ( error => {
59+ res . status ( 500 ) ;
60+ next ( error ) ;
61+ } ) ;
5762 }
5863
5964 function failure ( error ) {
Original file line number Diff line number Diff line change @@ -51,6 +51,20 @@ describe("FastBoot", function() {
5151 } ) ;
5252 } ) ;
5353
54+ it ( "responds with a chunked response" , function ( ) {
55+ let middleware = fastbootMiddleware ( {
56+ distPath : fixture ( 'basic-app' )
57+ } ) ;
58+ server = new TestHTTPServer ( middleware , { errorHandling : true } ) ;
59+
60+ return server . start ( )
61+ . then ( ( ) => server . request ( '/' , { resolveWithFullResponse : true } ) )
62+ . then ( ( { body, _, headers } ) => {
63+ expect ( headers [ 'transfer-encoding' ] ) . to . eq ( 'chunked' ) ;
64+ expect ( body ) . to . match ( / W e l c o m e t o E m b e r / ) ;
65+ } ) ;
66+ } ) ;
67+
5468 it ( "returns 404 when navigating to a URL that doesn't exist" , function ( ) {
5569 let middleware = fastbootMiddleware ( fixture ( 'basic-app' ) ) ;
5670 server = new TestHTTPServer ( middleware ) ;
You can’t perform that action at this time.
0 commit comments