mirror of https://github.com/status-im/metro.git
Add multipart response functionality to the full bundler created by Delta Bunlder
Reviewed By: jeanlauliac Differential Revision: D5825701 fbshipit-source-id: 481d36420396e2fcb457397905c69fb5720f43b2
This commit is contained in:
parent
61fb142520
commit
4f31807cf8
|
@ -883,6 +883,7 @@ class Server {
|
||||||
|
|
||||||
_prepareDeltaBundler(
|
_prepareDeltaBundler(
|
||||||
req: IncomingMessage,
|
req: IncomingMessage,
|
||||||
|
mres: MultipartResponse,
|
||||||
): {options: BundleOptions, buildID: string} {
|
): {options: BundleOptions, buildID: string} {
|
||||||
const options = this._getOptionsFromUrl(req.url);
|
const options = this._getOptionsFromUrl(req.url);
|
||||||
|
|
||||||
|
@ -890,6 +891,11 @@ class Server {
|
||||||
|
|
||||||
if (!this._opts.silent) {
|
if (!this._opts.silent) {
|
||||||
options.onProgress = (transformedFileCount, totalFileCount) => {
|
options.onProgress = (transformedFileCount, totalFileCount) => {
|
||||||
|
mres.writeChunk(
|
||||||
|
{'Content-Type': 'application/json'},
|
||||||
|
JSON.stringify({done: transformedFileCount, total: totalFileCount}),
|
||||||
|
);
|
||||||
|
|
||||||
this._reporter.update({
|
this._reporter.update({
|
||||||
buildID,
|
buildID,
|
||||||
type: 'bundle_transform_progressed',
|
type: 'bundle_transform_progressed',
|
||||||
|
@ -912,7 +918,8 @@ class Server {
|
||||||
req: IncomingMessage,
|
req: IncomingMessage,
|
||||||
res: ServerResponse,
|
res: ServerResponse,
|
||||||
) {
|
) {
|
||||||
const {options, buildID} = this._prepareDeltaBundler(req);
|
const mres = MultipartResponse.wrap(req, res);
|
||||||
|
const {options, buildID} = this._prepareDeltaBundler(req, mres);
|
||||||
|
|
||||||
const requestingBundleLogEntry = log(
|
const requestingBundleLogEntry = log(
|
||||||
createActionStartEntry({
|
createActionStartEntry({
|
||||||
|
@ -948,17 +955,20 @@ class Server {
|
||||||
req.headers['if-modified-since'] === result.lastModified.toUTCString()
|
req.headers['if-modified-since'] === result.lastModified.toUTCString()
|
||||||
) {
|
) {
|
||||||
debug('Responding with 304');
|
debug('Responding with 304');
|
||||||
res.writeHead(304);
|
mres.writeHead(304);
|
||||||
res.end();
|
mres.end();
|
||||||
} else {
|
} else {
|
||||||
res.setHeader(
|
mres.setHeader(
|
||||||
FILES_CHANGED_COUNT_HEADER,
|
FILES_CHANGED_COUNT_HEADER,
|
||||||
String(result.numModifiedFiles),
|
String(result.numModifiedFiles),
|
||||||
);
|
);
|
||||||
res.setHeader('Content-Type', 'application/javascript');
|
mres.setHeader('Content-Type', 'application/javascript');
|
||||||
res.setHeader('Last-Modified', result.lastModified.toUTCString());
|
mres.setHeader('Last-Modified', result.lastModified.toUTCString());
|
||||||
res.setHeader('Content-Length', String(Buffer.byteLength(result.bundle)));
|
mres.setHeader(
|
||||||
res.end(result.bundle);
|
'Content-Length',
|
||||||
|
String(Buffer.byteLength(result.bundle)),
|
||||||
|
);
|
||||||
|
mres.end(result.bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._reporter.update({
|
this._reporter.update({
|
||||||
|
@ -978,7 +988,8 @@ class Server {
|
||||||
req: IncomingMessage,
|
req: IncomingMessage,
|
||||||
res: ServerResponse,
|
res: ServerResponse,
|
||||||
) {
|
) {
|
||||||
const {options, buildID} = this._prepareDeltaBundler(req);
|
const mres = MultipartResponse.wrap(req, res);
|
||||||
|
const {options, buildID} = this._prepareDeltaBundler(req, mres);
|
||||||
|
|
||||||
const requestingBundleLogEntry = log(
|
const requestingBundleLogEntry = log(
|
||||||
createActionStartEntry({
|
createActionStartEntry({
|
||||||
|
@ -997,7 +1008,7 @@ class Server {
|
||||||
deltaBundleId: this.optionsHash(options),
|
deltaBundleId: this.optionsHash(options),
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this._handleError(res, this.optionsHash(options), error);
|
this._handleError(mres, this.optionsHash(options), error);
|
||||||
|
|
||||||
this._reporter.update({
|
this._reporter.update({
|
||||||
buildID,
|
buildID,
|
||||||
|
@ -1007,8 +1018,8 @@ class Server {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'application/json');
|
mres.setHeader('Content-Type', 'application/json');
|
||||||
res.end(sourceMap.toString());
|
mres.end(sourceMap.toString());
|
||||||
|
|
||||||
this._reporter.update({
|
this._reporter.update({
|
||||||
buildID,
|
buildID,
|
||||||
|
|
Loading…
Reference in New Issue