*Add temp hack to filter out inline source maps
This commit is contained in:
parent
2450390229
commit
67d94d1c47
|
@ -103,9 +103,11 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleProxy(details: OnRequestDetailsType): Promise<any> {
|
async handleProxy(details: OnRequestDetailsType): Promise<any> {
|
||||||
return requestProxies;
|
return requestProxies;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleReqHeaders(
|
async handleReqHeaders(
|
||||||
details: OnBeforeSendHeadersDetailsType
|
details: OnBeforeSendHeadersDetailsType
|
||||||
): Promise<BlockingResponse | boolean> {
|
): Promise<BlockingResponse | boolean> {
|
||||||
|
@ -247,35 +249,42 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
if (buffer.length) {
|
if (buffer.length) {
|
||||||
let mode = contentModes[contentType as string];
|
let mode = contentModes[contentType as string];
|
||||||
if (mode === CONTENT_MODE_BUFFERED) {
|
if (mode === CONTENT_MODE_BUFFERED) {
|
||||||
filter.write(
|
let data: string | Uint8Array = Uint8Array.from(
|
||||||
Uint8Array.from(
|
buffer.reduce(
|
||||||
buffer.reduce(
|
(previousValue: Uint8Array, currentValue: Uint8Array) => {
|
||||||
(previousValue: Uint8Array, currentValue: Uint8Array) => {
|
return Uint8Array.from([...previousValue, ...currentValue]);
|
||||||
return Uint8Array.from([...previousValue, ...currentValue]);
|
}
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
if (contentType === "application/javascript") {
|
||||||
|
data = new TextDecoder("utf-8", { fatal: true }).decode(data);
|
||||||
|
data = data.replace(
|
||||||
|
/\/\/#\s*sourceMappingURL=([^\.]+)\.js.map/,
|
||||||
|
""
|
||||||
|
);
|
||||||
|
data = new TextEncoder().encode(data);
|
||||||
|
}
|
||||||
|
filter.write(data);
|
||||||
} else if (mode == CONTENT_MODE_CHUNKED) {
|
} else if (mode == CONTENT_MODE_CHUNKED) {
|
||||||
buffer.forEach(filter.write);
|
buffer.forEach((data) => filter.write(data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filter.close();
|
filter.close();
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.log("page error", urlPath, e.message);
|
console.error("page error", urlPath, e.message);
|
||||||
/* if (
|
/* if (
|
||||||
urlPath.endsWith(".html") ||
|
urlPath.endsWith(".html") ||
|
||||||
urlPath.endsWith(".htm") ||
|
urlPath.endsWith(".htm") ||
|
||||||
urlPath.endsWith(".xhtml") ||
|
urlPath.endsWith(".xhtml") ||
|
||||||
urlPath.endsWith(".shtml")
|
urlPath.endsWith(".shtml")
|
||||||
) {
|
) {
|
||||||
this.setData(details, "contentType", "text/html");
|
this.setData(details, "contentType", "text/html");
|
||||||
let template = serverErrorTemplate();
|
let template = serverErrorTemplate();
|
||||||
contentLength = template.length;
|
contentLength = template.length;
|
||||||
receiveUpdate(new TextEncoder().encode(template));
|
receiveUpdate(new TextEncoder().encode(template));
|
||||||
this.setData(details, "contentLength", contentLength);
|
this.setData(details, "contentLength", contentLength);
|
||||||
}*/
|
}*/
|
||||||
filterPromise.then(() => streamPromise).then(() => filter.close());
|
filterPromise.then(() => streamPromise).then(() => filter.close());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -294,11 +303,11 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
});
|
});
|
||||||
|
|
||||||
/* if (contentLength) {
|
/* if (contentLength) {
|
||||||
headers.push({
|
headers.push({
|
||||||
name: "content-length",
|
name: "content-length",
|
||||||
value: contentLength,
|
value: contentLength,
|
||||||
});
|
});
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
return {
|
return {
|
||||||
responseHeaders: headers,
|
responseHeaders: headers,
|
||||||
|
|
Reference in New Issue