From 38a2913d34334a7a5c2bca38b8c1da396807effa Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Thu, 24 Nov 2022 12:05:40 -0700 Subject: [PATCH] Revert "add heapsnapshot route" This reverts commit 84d522c5a6475a24eca0448778d1af4562dcac80. https://github.com/bnoordhuis/node-heapdump/pull/159 --- app/routes/resources/heapsnapshot.ts | 49 ---------------------------- app/utils/misc.tsx | 2 +- package-lock.json | 34 ------------------- package.json | 2 -- 4 files changed, 1 insertion(+), 86 deletions(-) delete mode 100644 app/routes/resources/heapsnapshot.ts diff --git a/app/routes/resources/heapsnapshot.ts b/app/routes/resources/heapsnapshot.ts deleted file mode 100644 index af7b13986..000000000 --- a/app/routes/resources/heapsnapshot.ts +++ /dev/null @@ -1,49 +0,0 @@ -import path from 'path' -import os from 'os' -import fs from 'fs' -import heapdump from 'heapdump' -import {Response} from '@remix-run/node' -import {PassThrough} from 'stream' -import type {DataFunctionArgs} from '@remix-run/node' -import {requireAdminUser} from '~/utils/session.server' - -export async function loader({request}: DataFunctionArgs) { - await requireAdminUser(request) - const host = - request.headers.get('X-Forwarded-Host') ?? request.headers.get('host') - - const snapshotPath = await new Promise( - (resolve, reject) => { - const tempDir = os.tmpdir() - const filepath = path.join( - tempDir, - `${host}-heapdump-${Date.now()}.heapsnapshot`, - ) - console.log(`Writing heapdump to ${filepath}`) - heapdump.writeSnapshot(filepath, (err, filename) => { - if (err) reject(err) - resolve(filename) - }) - }, - ) - if (!snapshotPath) { - throw new Response('No snapshot saved', {status: 500}) - } - - const body = new PassThrough() - const stream = fs.createReadStream(snapshotPath) - stream.on('open', () => stream.pipe(body)) - stream.on('error', err => body.end(err)) - stream.on('end', () => body.end()) - - return new Response(body, { - status: 200, - headers: { - 'Content-Type': 'application/octet-stream', - 'Content-Disposition': `attachment; filename="${path.basename( - snapshotPath, - )}"`, - 'Content-Length': (await fs.promises.stat(snapshotPath)).size.toString(), - }, - }) -} diff --git a/app/utils/misc.tsx b/app/utils/misc.tsx index d42d646d0..9e602cfb6 100644 --- a/app/utils/misc.tsx +++ b/app/utils/misc.tsx @@ -238,7 +238,7 @@ function getDiscordAuthorizeURL(domainUrl: string) { } /** - * @returns domain URL (without a ending slash, like: https://kentcdodds.com) + * @returns domain URL (without a ending slash) */ function getDomainUrl(request: Request) { const host = diff --git a/package-lock.json b/package-lock.json index d07569f0c..04c558429 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,6 @@ "gsap": "^3.11.3", "hast-util-to-html": "^8.0.3", "hast-util-to-string": "^2.0.0", - "heapdump": "^0.3.15", "lodash": "^4.17.21", "lru-cache": "^7.14.1", "match-sorter": "^6.3.1", @@ -118,7 +117,6 @@ "@types/dom-mediacapture-record": "^1.0.13", "@types/express-http-proxy": "^1.6.3", "@types/fs-extra": "^9.0.13", - "@types/heapdump": "^0.3.1", "@types/jest": "^29.2.3", "@types/lodash": "^4.14.189", "@types/morgan": "^1.9.3", @@ -6354,12 +6352,6 @@ "@types/unist": "*" } }, - "node_modules/@types/heapdump": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@types/heapdump/-/heapdump-0.3.1.tgz", - "integrity": "sha512-1BaXjnso0bPxgG+Ngh1RKXxyjaugFN++xlXZxdRQxQVosIQf7DuJ6PiIRMCQJfL3MJRe02+zp8ApTsza3sCMgg==", - "dev": true - }, "node_modules/@types/http-cache-semantics": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz", @@ -13592,18 +13584,6 @@ "integrity": "sha512-tWCK4biJ6hcLqTviLXVR9DTRfYGQMXEIUj3gwJ2rZ5wO/at3XtkI4g8mCvFdUF9l1KMBNCfmNAdnahm1cgavQA==", "dev": true }, - "node_modules/heapdump": { - "version": "0.3.15", - "resolved": "https://registry.npmjs.org/heapdump/-/heapdump-0.3.15.tgz", - "integrity": "sha512-n8aSFscI9r3gfhOcAECAtXFaQ1uy4QSke6bnaL+iymYZ/dWs9cqDqHM+rALfsHUwukUbxsdlECZ0pKmJdQ/4OA==", - "hasInstallScript": true, - "dependencies": { - "nan": "^2.13.2" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/hey-listen": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/hey-listen/-/hey-listen-1.0.8.tgz", @@ -32934,12 +32914,6 @@ "@types/unist": "*" } }, - "@types/heapdump": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@types/heapdump/-/heapdump-0.3.1.tgz", - "integrity": "sha512-1BaXjnso0bPxgG+Ngh1RKXxyjaugFN++xlXZxdRQxQVosIQf7DuJ6PiIRMCQJfL3MJRe02+zp8ApTsza3sCMgg==", - "dev": true - }, "@types/http-cache-semantics": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz", @@ -38303,14 +38277,6 @@ "integrity": "sha512-tWCK4biJ6hcLqTviLXVR9DTRfYGQMXEIUj3gwJ2rZ5wO/at3XtkI4g8mCvFdUF9l1KMBNCfmNAdnahm1cgavQA==", "dev": true }, - "heapdump": { - "version": "0.3.15", - "resolved": "https://registry.npmjs.org/heapdump/-/heapdump-0.3.15.tgz", - "integrity": "sha512-n8aSFscI9r3gfhOcAECAtXFaQ1uy4QSke6bnaL+iymYZ/dWs9cqDqHM+rALfsHUwukUbxsdlECZ0pKmJdQ/4OA==", - "requires": { - "nan": "^2.13.2" - } - }, "hey-listen": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/hey-listen/-/hey-listen-1.0.8.tgz", diff --git a/package.json b/package.json index 2e02be388..ecebab267 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,6 @@ "gsap": "^3.11.3", "hast-util-to-html": "^8.0.3", "hast-util-to-string": "^2.0.0", - "heapdump": "^0.3.15", "lodash": "^4.17.21", "lru-cache": "^7.14.1", "match-sorter": "^6.3.1", @@ -158,7 +157,6 @@ "@types/dom-mediacapture-record": "^1.0.13", "@types/express-http-proxy": "^1.6.3", "@types/fs-extra": "^9.0.13", - "@types/heapdump": "^0.3.1", "@types/jest": "^29.2.3", "@types/lodash": "^4.14.189", "@types/morgan": "^1.9.3",