File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,12 +56,16 @@ const createServer = (domain = process.env["HOST"] || "localhost"): HttpsLocalho
5656 app . serve = function ( staticPath = process . cwd ( ) , port = Number ( process . env [ "PORT" ] ) || 443 ) {
5757 const p404 = staticPath + "/404.html"
5858 const index = staticPath + "/index.html"
59- const fallbackPath = fs . existsSync ( p404 ) ? p404 : fs . existsSync ( index ) ? index : undefined
59+ const fallback = fs . existsSync ( p404 )
60+ ? { status : 404 , file : path . resolve ( p404 ) }
61+ : fs . existsSync ( index )
62+ ? { status : 200 , file : path . resolve ( index ) }
63+ : undefined
6064
6165 app . use ( express . static ( staticPath ) )
66+ // codeql[js/missing-rate-limiting]
6267 app . use ( ( _req : Request , res : Response ) => {
63- if ( fallbackPath === p404 ) res . status ( 404 ) . sendFile ( path . resolve ( p404 ) )
64- else if ( fallbackPath === index ) res . status ( 200 ) . sendFile ( path . resolve ( index ) )
68+ if ( fallback ) res . status ( fallback . status ) . sendFile ( fallback . file )
6569 else res . status ( 404 ) . send ( "Not found." )
6670 } )
6771 console . info ( "Serving static path: " + staticPath )
You can’t perform that action at this time.
0 commit comments