diff options
Diffstat (limited to 'src/server/server_Initialization.ts')
-rw-r--r-- | src/server/server_Initialization.ts | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/server/server_Initialization.ts b/src/server/server_Initialization.ts index de93b64c3..d1b9d8cf2 100644 --- a/src/server/server_Initialization.ts +++ b/src/server/server_Initialization.ts @@ -92,6 +92,13 @@ function buildWithMiddleware(server: express.Express) { passport.session(), (req: express.Request, res: express.Response, next: express.NextFunction) => { res.locals.user = req.user; + if (req.originalUrl.endsWith(".png") && req.method === 'GET') { + const period = 30000; + res.set('Cache-control', `public, max-age=${period}`); + } else { + // for the other requests set strict no caching parameters + res.set('Cache-control', `no-store`); + } next(); } ].forEach(next => server.use(next)); @@ -178,11 +185,21 @@ 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') + .replace('<head>', '<head> <style>[id ^= "google"] { display: none; } </style>') + // .replace(/href="http([^"]*)"/g, replacer) + .replace(/target="_blank"/g, "")); + rewrittenHtmlBody = zlib.gzipSync(htmlText); + } else { + console.log("EMPTY body: href"); + } } catch (e) { console.log(e); } } }); |