aboutsummaryrefslogtreecommitdiff
path: root/src/server/server_Initialization.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2022-04-29 20:37:22 -0400
committerbobzel <zzzman@gmail.com>2022-04-29 20:37:22 -0400
commit10dda7683987a7d0735478374af1a256bca8e7f1 (patch)
tree6e3115d3313265c487e0043852972201a234fc4f /src/server/server_Initialization.ts
parent55a5322fffc09bde04ef8b466e19b701bad2762b (diff)
another fix for Label's BigText to make multiline work better. fixed server bug for 'write after end' when servering web pages.
Diffstat (limited to 'src/server/server_Initialization.ts')
-rw-r--r--src/server/server_Initialization.ts25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/server/server_Initialization.ts b/src/server/server_Initialization.ts
index 24cc3b796..81ed0d2a1 100644
--- a/src/server/server_Initialization.ts
+++ b/src/server/server_Initialization.ts
@@ -193,11 +193,11 @@ function proxyServe(req: any, requrl: string, response: any) {
return `href="${resolvedServerUrl + "/corsProxy/http" + href}"`;
};
const zipToStringDecoder = new (require('string_decoder').StringDecoder)('utf8');
- // const htmlText = zipToStringDecoder.write(zlib.gunzipSync(htmlBodyMemoryStream.read()).toString('utf8')
- // .replace('<head>', '<head> <style>[id ^= "google"] { display: none; } </style>')
- // .replace(/href="http([^"]*)"/g, replacer)
- // .replace(/target="_blank"/g, ""));
- // rewrittenHtmlBody = zlib.gzipSync(htmlText);
+ const htmlText = zipToStringDecoder.write(zlib.gunzipSync(htmlBodyMemoryStream.read()).toString('utf8')
+ .replace('<head>', '<head> <style>[id ^= "google"] { display: none; } </style>')
+ .replace(/href="http([^"]*)"/g, replacer)
+ .replace(/target="_blank"/g, ""));
+ rewrittenHtmlBody = zlib.gzipSync(htmlText);
const bodyStream = htmlBodyMemoryStream.read();
if (bodyStream) {
const htmlText = zipToStringDecoder.write(zlib.gunzipSync(bodyStream).toString('utf8')
@@ -208,14 +208,25 @@ function proxyServe(req: any, requrl: string, response: any) {
} else {
console.log("EMPTY body: href");
}
- } catch (e) { console.log(e); }
+ } catch (e) {
+ console.log("EROR?: ", e);
+ }
}
});
})
.on('data', (e: any) => {
- rewrittenHtmlBody && response.send(rewrittenHtmlBody);
+ try {
+ if (!response.connection.writable) {
+ rewrittenHtmlBody && response.send(rewrittenHtmlBody);
+ }
+ } catch (e) {
+ console.log("ERROR data : ", e);
+ }
rewrittenHtmlBody = undefined;
})
+ .on('error', (e: any) => {
+ console.log("ERROR ON SERVER: ", e);
+ })
.pipe(response);
})
.pipe(htmlBodyMemoryStream);