@@ -27,7 +27,7 @@ import path from 'node:path'
2727import { fileURLToPath } from 'node:url'
2828import express from 'express'
2929import type { Har } from 'har-format'
30- import { CORPUS , type CorpusEntry } from './corpus/_corpus-index'
30+ import { CORPUS } from './corpus/_corpus-index'
3131
3232const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
3333const app = express ( )
@@ -41,7 +41,11 @@ const harCache = new Map<string, Har>()
4141
4242// Extract URL parts for location patching
4343function getUrlParts ( key : string ) {
44- const originalUrl = CORPUS [ key ] . url
44+ const entry = CORPUS [ key ]
45+ if ( ! entry ) {
46+ throw new Error ( `Corpus entry not found: ${ key } ` )
47+ }
48+ const originalUrl = entry . url
4549 const url = new URL ( originalUrl )
4650 return {
4751 host : url . host ,
@@ -77,7 +81,9 @@ app.get('/', async (_req, res) => {
7781 try {
7882 const links = Object . entries ( CORPUS )
7983 . map ( ( [ key , entry ] ) => {
80- const description = entry . description ? `<div style="color: #666; font-size: 0.9em; margin-top: 5px;">${ entry . description } </div>` : ''
84+ const description = entry . description
85+ ? `<div style="color: #666; font-size: 0.9em; margin-top: 5px;">${ entry . description } </div>`
86+ : ''
8187 return `
8288 <li>
8389 <div style="margin-bottom: 10px;">
@@ -143,14 +149,16 @@ app.get('/', async (_req, res) => {
143149// Serve the main page from corpus
144150app . get ( '/corpus/:key/:mode(clean|gitcasso)' , async ( req , res ) => {
145151 try {
146- const key = req . params . key
147- const mode = req . params . mode as 'clean' | 'gitcasso'
152+ // biome-ignore lint/complexity/useLiteralKeys: type comes from path string
153+ const key = req . params [ 'key' ]
154+ // biome-ignore lint/complexity/useLiteralKeys: type comes from path string
155+ const mode = req . params [ 'mode' ] as 'clean' | 'gitcasso'
148156
149- if ( ! ( key in CORPUS ) ) {
157+ if ( ! key || ! ( key in CORPUS ) ) {
150158 return res . status ( 400 ) . send ( 'Invalid key - not found in CORPUS' )
151159 }
152160
153- const entry = CORPUS [ key ]
161+ const entry = CORPUS [ key ] !
154162
155163 if ( entry . type === 'har' ) {
156164 // Handle HAR corpus
@@ -216,11 +224,11 @@ app.get('/corpus/:key/:mode(clean|gitcasso)', async (req, res) => {
216224app . get ( '/asset/:key/*' , async ( req , res ) => {
217225 try {
218226 const key = req . params . key
219- if ( ! ( key in CORPUS ) ) {
227+ if ( ! key || ! ( key in CORPUS ) ) {
220228 return res . status ( 400 ) . send ( 'Invalid key - not found in CORPUS' )
221229 }
222230
223- const entry = CORPUS [ key ]
231+ const entry = CORPUS [ key ] !
224232 if ( entry . type !== 'har' ) {
225233 return res . status ( 400 ) . send ( 'Asset serving only available for HAR corpus' )
226234 }
@@ -528,4 +536,4 @@ function injectGitcassoScript(key: string, html: string) {
528536 throw error ( 'No closing body tag, nowhere to put the content script!' )
529537 }
530538 return html . replace ( '</body>' , `${ contentScriptTag } </body>` )
531- }
539+ }
0 commit comments