mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-09-02 17:10:48 +02:00
handle memory issues
This commit is contained in:
+13
-1
@@ -93,7 +93,19 @@ export default async function start() {
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
app.use(compression());
|
||||
app.use(
|
||||
compression({
|
||||
filter: (req, res) => {
|
||||
// Skip compression for streamed file content — these responses are
|
||||
// piped from the streamer and can be very large. Compressing them
|
||||
// forces the middleware to hold per-response zlib buffers that pile
|
||||
// up under concurrent load and contribute to heap exhaustion.
|
||||
// Binary files (images, archives) barely compress anyway.
|
||||
if (req.path.match(/^\/api\/repo\/.+\/file\//)) return false;
|
||||
return compression.filter(req, res);
|
||||
},
|
||||
})
|
||||
);
|
||||
app.set("etag", "strong");
|
||||
|
||||
// handle session and connection
|
||||
|
||||
@@ -149,10 +149,14 @@ async function webView(req: express.Request, res: express.Response) {
|
||||
});
|
||||
}
|
||||
if (f.extension() == "md") {
|
||||
const content = await streamToString(await f.anonymizedContent());
|
||||
const body = sanitizeHtml(marked.marked(content, { headerIds: false, mangle: false }), sanitizeOptions);
|
||||
const html = `<!DOCTYPE html><html><head><title>Content</title></head><link rel="stylesheet" href="/css/all.min.css" /><body><div class="container p-3 file-content markdown-body">${body}</div></body></html>`;
|
||||
res.contentType("text/html").send(html);
|
||||
try {
|
||||
const content = await streamToString(await f.anonymizedContent());
|
||||
const body = sanitizeHtml(marked.marked(content, { headerIds: false, mangle: false }), sanitizeOptions);
|
||||
const html = `<!DOCTYPE html><html><head><title>Content</title></head><link rel="stylesheet" href="/css/all.min.css" /><body><div class="container p-3 file-content markdown-body">${body}</div></body></html>`;
|
||||
res.contentType("text/html").send(html);
|
||||
} catch {
|
||||
f.send(res);
|
||||
}
|
||||
} else {
|
||||
f.send(res);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user