@@ -18,9 +18,9 @@ import generateETag from 'etag'
1818import getAvailablePort from 'get-port'
1919import httpProxy from 'http-proxy'
2020import { createProxyMiddleware } from 'http-proxy-middleware'
21- import { jwtDecode } from 'jwt-decode'
21+ import { jwtDecode , type JwtPayload } from 'jwt-decode'
2222import { locatePath } from 'locate-path'
23- import { Match } from 'netlify-redirector'
23+ import type { Match } from 'netlify-redirector'
2424import pFilter from 'p-filter'
2525import throttle from 'lodash/throttle.js'
2626
@@ -102,8 +102,7 @@ const injectHtml = async function (
102102 return await compressResponseBody ( bodyWithInjections , proxyRes . headers [ 'content-encoding' ] )
103103}
104104
105- // @ts -expect-error TS(7006) FIXME: Parameter 'errorBuffer' implicitly has an 'any' ty... Remove this comment to see the full error message
106- const formatEdgeFunctionError = ( errorBuffer , acceptsHtml ) => {
105+ const formatEdgeFunctionError = ( errorBuffer : Buffer < ArrayBufferLike > , acceptsHtml : boolean ) : string => {
107106 const {
108107 error : { message, name, stack } ,
109108 } = JSON . parse ( errorBuffer . toString ( ) )
@@ -156,13 +155,11 @@ const isEndpointExists = async function (endpoint: string, origin: string) {
156155 }
157156}
158157
159- // @ts -expect-error TS(7006) FIXME: Parameter 'match' implicitly has an 'any' type.
160- const isExternal = function ( match ) {
161- return match . to && match . to . match ( / ^ h t t p s ? : \/ \/ / )
158+ const isExternal = function ( match : Match ) {
159+ return 'to' in match && match . to . match ( / ^ h t t p s ? : \/ \/ / )
162160}
163161
164- // @ts -expect-error TS(7031) FIXME: Binding element 'hash' implicitly has an 'any' typ... Remove this comment to see the full error message
165- const stripOrigin = function ( { hash, pathname, search } ) {
162+ const stripOrigin = function ( { hash, pathname, search } : URL ) : string {
166163 return `${ pathname } ${ search } ${ hash } `
167164}
168165
@@ -189,21 +186,18 @@ const proxyToExternalUrl = function ({
189186 return handler ( req , res , ( ) => { } )
190187}
191188
192- // @ts -expect-error TS(7031) FIXME: Binding element 'addonUrl' implicitly has an 'any'... Remove this comment to see the full error message
193- const handleAddonUrl = function ( { addonUrl, req, res } ) {
189+ const handleAddonUrl = function ( { addonUrl, req, res } : { req : Request ; res : ServerResponse ; addonUrl : string } ) {
194190 const dest = new URL ( addonUrl )
195191 const destURL = stripOrigin ( dest )
196192
197193 return proxyToExternalUrl ( { req, res, dest, destURL } )
198194}
199195
200- // @ts -expect-error TS(7006) FIXME: Parameter 'match' implicitly has an 'any' type.
201- const isRedirect = function ( match ) {
202- return match . status && match . status >= 300 && match . status <= 400
196+ const isRedirect = function ( match : Match ) {
197+ return 'status' in match && match . status >= 300 && match . status <= 400
203198}
204199
205- // @ts -expect-error TS(7006) FIXME: Parameter 'publicFolder' implicitly has an 'any' t... Remove this comment to see the full error message
206- const render404 = async function ( publicFolder ) {
200+ const render404 = async function ( publicFolder : string ) {
207201 const maybe404Page = path . resolve ( publicFolder , '404.html' )
208202 try {
209203 const isFile = await isFileAsync ( maybe404Page )
@@ -219,8 +213,7 @@ const render404 = async function (publicFolder) {
219213// Used as an optimization to avoid dual lookups for missing assets
220214const assetExtensionRegExp = / \. ( h t m l ? | p n g | j p g | j s | c s s | s v g | g i f | i c o | w o f f | w o f f 2 ) $ /
221215
222- // @ts -expect-error TS(7006) FIXME: Parameter 'url' implicitly has an 'any' type.
223- const alternativePathsFor = function ( url ) {
216+ const alternativePathsFor = function ( url : string ) {
224217 if ( isFunction ( true , url ) ) {
225218 return [ ]
226219 }
@@ -317,9 +310,9 @@ const serveRedirect = async function ({
317310 req . url = '/.netlify/non-existent-path'
318311
319312 if ( token ) {
320- let jwtValue = { }
313+ let jwtValue : JwtPayload = { }
321314 try {
322- jwtValue = jwtDecode ( token ) || { }
315+ jwtValue = jwtDecode ( token )
323316 } catch ( error ) {
324317 // @ts -expect-error TS(2571) FIXME: Object is of type 'unknown'.
325318 console . warn ( NETLIFYDEVWARN , 'Error while decoding JWT provided in request' , error . message )
@@ -328,7 +321,6 @@ const serveRedirect = async function ({
328321 return
329322 }
330323
331- // @ts -expect-error TS(2339) FIXME: Property 'exp' does not exist on type '{}'.
332324 if ( ( jwtValue . exp || 0 ) < Math . round ( Date . now ( ) / MILLISEC_TO_SEC ) ) {
333325 console . warn ( NETLIFYDEVWARN , 'Expired JWT provided in request' , req . url )
334326 } else {
@@ -462,10 +454,9 @@ const serveRedirect = async function ({
462454 return proxy . web ( req , res , options )
463455}
464456
465- // @ts -expect-error TS(7006) FIXME: Parameter 'req' implicitly has an 'any' type.
466- const reqToURL = function ( req , pathname ) {
457+ const reqToURL = function ( req : Request , pathname : undefined | string ) {
467458 return new URL (
468- pathname ,
459+ pathname ?? '' ,
469460 `${ req . protocol || ( req . headers . scheme && `${ req . headers . scheme } :` ) || 'http:' } //${
470461 req . headers . host || req . hostname
471462 } `,
@@ -612,10 +603,8 @@ const initializeProxy = async function ({
612603 } )
613604 }
614605
615- // @ts -expect-error TS(7034) FIXME: Variable 'responseData' implicitly has type 'any[]... Remove this comment to see the full error message
616- const responseData = [ ]
617- // @ts -expect-error TS(2345) FIXME: Argument of type 'string | undefined' is not assig... Remove this comment to see the full error message
618- const requestURL = new URL ( req . url , `http://${ req . headers . host || '127.0.0.1' } ` )
606+ const responseData : Uint8Array [ ] = [ ]
607+ const requestURL = new URL ( req . url ?? '' , `http://${ req . headers . host || '127.0.0.1' } ` )
619608 const headersRules = headersForPath ( headers , requestURL . pathname )
620609
621610 const htmlInjections =
@@ -649,11 +638,10 @@ const initializeProxy = async function ({
649638 }
650639
651640 proxyRes . on ( 'data' , function onData ( data ) {
652- responseData . push ( data )
641+ responseData . push ( data as Uint8Array )
653642 } )
654643
655644 proxyRes . on ( 'end' , async function onEnd ( ) {
656- // @ts -expect-error TS(7005) FIXME: Variable 'responseData' implicitly has an 'any[]' ... Remove this comment to see the full error message
657645 let responseBody = Buffer . concat ( responseData )
658646
659647 // @ts -expect-error TS(2339) FIXME: Property 'proxyOptions' does not exist on type 'In... Remove this comment to see the full error message
@@ -684,7 +672,7 @@ const initializeProxy = async function ({
684672 const isUncaughtError = proxyRes . headers [ 'x-nf-uncaught-error' ] === '1'
685673
686674 if ( isEdgeFunctionsRequest ( req ) && isUncaughtError ) {
687- const acceptsHtml = req . headers && req . headers . accept && req . headers . accept . includes ( 'text/html' )
675+ const acceptsHtml = req . headers ?. accept ?. includes ( 'text/html' ) ?? false
688676 const decompressedBody = await decompressResponseBody ( responseBody , proxyRes . headers [ 'content-encoding' ] )
689677 const formattedBody = formatEdgeFunctionError ( decompressedBody , acceptsHtml )
690678 const errorResponse = acceptsHtml
@@ -777,16 +765,13 @@ const onRequest = async (
777765 if ( functionMatch ) {
778766 // Setting an internal header with the function name so that we don't
779767 // have to match the URL again in the functions server.
780- /** @type {Record<string, string> } */
781- const headers = { }
768+ const headers : Record < string , string > = { }
782769
783770 if ( functionMatch . func ) {
784- // @ts -expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
785771 headers [ NFFunctionName ] = functionMatch . func . name
786772 }
787773
788774 if ( functionMatch . route ) {
789- // @ts -expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
790775 headers [ NFFunctionRoute ] = functionMatch . route . pattern
791776 }
792777
@@ -815,7 +800,7 @@ const onRequest = async (
815800 if ( match ) {
816801 // We don't want to generate an ETag for 3xx redirects.
817802 // @ts -expect-error TS(7031) FIXME: Binding element 'statusCode' implicitly has an 'an... Remove this comment to see the full error message
818- req [ shouldGenerateETag ] = ( { statusCode } ) => statusCode < 300 || statusCode >= 400
803+ req [ shouldGenerateETag ] = ( { statusCode } : { statusCode : number } ) => statusCode < 300 || statusCode >= 400
819804
820805 return serveRedirect ( { req, res, proxy, imageProxy, match, options, siteInfo, env, functionsRegistry } )
821806 }
@@ -824,7 +809,7 @@ const onRequest = async (
824809 // generate an ETag unless we're rendering an error page. The only way for
825810 // us to know that is by looking at the status code
826811 // @ts -expect-error TS(7031) FIXME: Binding element 'statusCode' implicitly has an 'an... Remove this comment to see the full error message
827- req [ shouldGenerateETag ] = ( { statusCode } ) => statusCode >= 200 && statusCode < 300
812+ req [ shouldGenerateETag ] = ( { statusCode } : { statusCode : number } ) => statusCode >= 200 && statusCode < 300
828813
829814 const hasFormSubmissionHandler : boolean =
830815 functionsRegistry && getFormHandler ( { functionsRegistry, logWarning : false } )
0 commit comments