fastboot-express-middleware
Advanced tools
Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "fastboot-express-middleware", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "An Express middleware for rendering Ember apps with FastBoot", | ||
@@ -41,5 +41,5 @@ "main": "src/index.js", | ||
"chalk": "^2.0.1", | ||
"fastboot": "^1.1.0", | ||
"fastboot": "^1.1.2", | ||
"request": "^2.81.0" | ||
} | ||
} |
@@ -92,2 +92,18 @@ # FastBoot Express Middleware | ||
## Response chunking | ||
By default, the middleware writes the complete response at once but response | ||
chunking (aka HTTP Streaming) is available via a config switch: | ||
```js | ||
app.get('/*', fastbootMiddleware({ | ||
distPath: '/path/to/dist', | ||
chunkedResponse: true | ||
})); | ||
``` | ||
Enabling response chunking will result in the response being delivered in | ||
multiple chunks (one for the head, one for the body and one for each shoebox) | ||
which helps getting the HTML to clients faster. | ||
[ember-cli-fastboot]: https://github.com/ember-fastboot/ember-cli-fastboot | ||
@@ -94,0 +110,0 @@ |
@@ -35,24 +35,33 @@ 'use strict'; | ||
function success(result) { | ||
result.html() | ||
.then(html => { | ||
let headers = result.headers; | ||
let statusMessage = result.error ? 'NOT OK ' : 'OK '; | ||
let responseBody = opts.chunkedResponse ? result.chunks() : result.html(); | ||
for (var pair of headers.entries()) { | ||
res.set(pair[0], pair[1]); | ||
} | ||
responseBody.then(body => { | ||
let headers = result.headers; | ||
let statusMessage = result.error ? 'NOT OK ' : 'OK '; | ||
for (var pair of headers.entries()) { | ||
res.set(pair[0], pair[1]); | ||
} | ||
if (result.error) { | ||
log("RESILIENT MODE CAUGHT:", result.error.stack); | ||
next(result.error); | ||
} | ||
log(result.statusCode, statusMessage + path); | ||
res.status(result.statusCode); | ||
if (result.error) { | ||
log("RESILIENT MODE CAUGHT:", result.error.stack); | ||
next(result.error); | ||
} | ||
log(result.statusCode, statusMessage + path); | ||
res.status(result.statusCode); | ||
res.send(html); | ||
}) | ||
.catch(error => { | ||
res.status(500); | ||
next(error); | ||
}); | ||
if (typeof body === 'string') { | ||
res.send(body); | ||
} else if (result.error) { | ||
res.send(body[0]); | ||
} else { | ||
body.forEach(chunk => res.write(chunk)); | ||
res.end(); | ||
} | ||
}) | ||
.catch(error => { | ||
res.status(500); | ||
next(error); | ||
}); | ||
} | ||
@@ -59,0 +68,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
155239
74
113
0
6
Updatedfastboot@^1.1.2