1+ import { error } from 'node:console'
12import fs from 'node:fs/promises'
23import path from 'node:path'
34import { fileURLToPath } from 'node:url'
45import express from 'express'
56import type { Har } from 'har-format'
67import { PAGES } from './har-index'
7- import { error } from 'node:console'
88
99const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
1010const app = express ( )
@@ -147,24 +147,26 @@ app.get('/har/:key/:mode(clean|gitcasso)', async (req, res) => {
147147 // Find the main HTML response
148148 const harData = await loadHar ( key )
149149 const originalUrl = PAGES [ key ]
150- const mainEntry = harData . log . entries . find (
151- ( entry ) =>
152- entry . request . url === originalUrl &&
153- entry . response . content . mimeType ?. includes ( 'text/html' ) &&
154- entry . response . content . text ,
155- ) || harData . log . entries . find (
156- ( entry ) =>
157- entry . response . status === 200 &&
158- entry . response . content . mimeType ?. includes ( 'text/html' ) &&
159- entry . response . content . text ,
160- )
150+ const mainEntry =
151+ harData . log . entries . find (
152+ ( entry ) =>
153+ entry . request . url === originalUrl &&
154+ entry . response . content . mimeType ?. includes ( 'text/html' ) &&
155+ entry . response . content . text ,
156+ ) ||
157+ harData . log . entries . find (
158+ ( entry ) =>
159+ entry . response . status === 200 &&
160+ entry . response . content . mimeType ?. includes ( 'text/html' ) &&
161+ entry . response . content . text ,
162+ )
161163 if ( ! mainEntry ) {
162164 return res . status ( 404 ) . send ( 'No HTML content found in HAR file' )
163165 }
164166
165167 // Extract all domains from HAR entries for dynamic replacement
166168 const domains = new Set < string > ( )
167- harData . log . entries . forEach ( entry => {
169+ harData . log . entries . forEach ( ( entry ) => {
168170 try {
169171 const url = new URL ( entry . request . url )
170172 domains . add ( url . hostname )
@@ -175,7 +177,7 @@ app.get('/har/:key/:mode(clean|gitcasso)', async (req, res) => {
175177
176178 // Replace external URLs with local asset URLs
177179 let html = mainEntry . response . content . text !
178- domains . forEach ( domain => {
180+ domains . forEach ( ( domain ) => {
179181 const escapedDomain = domain . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' )
180182 const regex = new RegExp ( `https?://${ escapedDomain } ` , 'g' )
181183 html = html . replace ( regex , `/asset/${ key } ` )
@@ -306,4 +308,3 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
306308 }
307309 return html . replace ( '</body>' , `${ contentScriptTag } </body>` )
308310}
309-
0 commit comments