1
+ import { error } from 'node:console'
1
2
import fs from 'node:fs/promises'
2
3
import path from 'node:path'
3
4
import { fileURLToPath } from 'node:url'
4
5
import express from 'express'
5
6
import type { Har } from 'har-format'
6
7
import { PAGES } from './har-index'
7
- import { error } from 'node:console'
8
8
9
9
const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
10
10
const app = express ( )
@@ -147,24 +147,26 @@ app.get('/har/:key/:mode(clean|gitcasso)', async (req, res) => {
147
147
// Find the main HTML response
148
148
const harData = await loadHar ( key )
149
149
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
+ )
161
163
if ( ! mainEntry ) {
162
164
return res . status ( 404 ) . send ( 'No HTML content found in HAR file' )
163
165
}
164
166
165
167
// Extract all domains from HAR entries for dynamic replacement
166
168
const domains = new Set < string > ( )
167
- harData . log . entries . forEach ( entry => {
169
+ harData . log . entries . forEach ( ( entry ) => {
168
170
try {
169
171
const url = new URL ( entry . request . url )
170
172
domains . add ( url . hostname )
@@ -175,7 +177,7 @@ app.get('/har/:key/:mode(clean|gitcasso)', async (req, res) => {
175
177
176
178
// Replace external URLs with local asset URLs
177
179
let html = mainEntry . response . content . text !
178
- domains . forEach ( domain => {
180
+ domains . forEach ( ( domain ) => {
179
181
const escapedDomain = domain . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' )
180
182
const regex = new RegExp ( `https?://${ escapedDomain } ` , 'g' )
181
183
html = html . replace ( regex , `/asset/${ key } ` )
@@ -306,4 +308,3 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
306
308
}
307
309
return html . replace ( '</body>' , `${ contentScriptTag } </body>` )
308
310
}
309
-
0 commit comments