@@ -18,9 +18,9 @@ import generateETag from 'etag'
18
18
import getAvailablePort from 'get-port'
19
19
import httpProxy from 'http-proxy'
20
20
import { createProxyMiddleware } from 'http-proxy-middleware'
21
- import { jwtDecode } from 'jwt-decode'
21
+ import { jwtDecode , type JwtPayload } from 'jwt-decode'
22
22
import { locatePath } from 'locate-path'
23
- import { Match } from 'netlify-redirector'
23
+ import type { Match } from 'netlify-redirector'
24
24
import pFilter from 'p-filter'
25
25
import throttle from 'lodash/throttle.js'
26
26
@@ -102,8 +102,7 @@ const injectHtml = async function (
102
102
return await compressResponseBody ( bodyWithInjections , proxyRes . headers [ 'content-encoding' ] )
103
103
}
104
104
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 => {
107
106
const {
108
107
error : { message, name, stack } ,
109
108
} = JSON . parse ( errorBuffer . toString ( ) )
@@ -156,13 +155,11 @@ const isEndpointExists = async function (endpoint: string, origin: string) {
156
155
}
157
156
}
158
157
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 ? : \/ \/ / )
162
160
}
163
161
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 {
166
163
return `${ pathname } ${ search } ${ hash } `
167
164
}
168
165
@@ -189,21 +186,18 @@ const proxyToExternalUrl = function ({
189
186
return handler ( req , res , ( ) => { } )
190
187
}
191
188
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 } ) {
194
190
const dest = new URL ( addonUrl )
195
191
const destURL = stripOrigin ( dest )
196
192
197
193
return proxyToExternalUrl ( { req, res, dest, destURL } )
198
194
}
199
195
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
203
198
}
204
199
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 ) {
207
201
const maybe404Page = path . resolve ( publicFolder , '404.html' )
208
202
try {
209
203
const isFile = await isFileAsync ( maybe404Page )
@@ -219,8 +213,7 @@ const render404 = async function (publicFolder) {
219
213
// Used as an optimization to avoid dual lookups for missing assets
220
214
const 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 ) $ /
221
215
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 ) {
224
217
if ( isFunction ( true , url ) ) {
225
218
return [ ]
226
219
}
@@ -317,9 +310,9 @@ const serveRedirect = async function ({
317
310
req . url = '/.netlify/non-existent-path'
318
311
319
312
if ( token ) {
320
- let jwtValue = { }
313
+ let jwtValue : JwtPayload = { }
321
314
try {
322
- jwtValue = jwtDecode ( token ) || { }
315
+ jwtValue = jwtDecode ( token )
323
316
} catch ( error ) {
324
317
// @ts -expect-error TS(2571) FIXME: Object is of type 'unknown'.
325
318
console . warn ( NETLIFYDEVWARN , 'Error while decoding JWT provided in request' , error . message )
@@ -328,7 +321,6 @@ const serveRedirect = async function ({
328
321
return
329
322
}
330
323
331
- // @ts -expect-error TS(2339) FIXME: Property 'exp' does not exist on type '{}'.
332
324
if ( ( jwtValue . exp || 0 ) < Math . round ( Date . now ( ) / MILLISEC_TO_SEC ) ) {
333
325
console . warn ( NETLIFYDEVWARN , 'Expired JWT provided in request' , req . url )
334
326
} else {
@@ -462,10 +454,9 @@ const serveRedirect = async function ({
462
454
return proxy . web ( req , res , options )
463
455
}
464
456
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 ) {
467
458
return new URL (
468
- pathname ,
459
+ pathname ?? '' ,
469
460
`${ req . protocol || ( req . headers . scheme && `${ req . headers . scheme } :` ) || 'http:' } //${
470
461
req . headers . host || req . hostname
471
462
} `,
@@ -612,10 +603,8 @@ const initializeProxy = async function ({
612
603
} )
613
604
}
614
605
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' } ` )
619
608
const headersRules = headersForPath ( headers , requestURL . pathname )
620
609
621
610
const htmlInjections =
@@ -649,11 +638,10 @@ const initializeProxy = async function ({
649
638
}
650
639
651
640
proxyRes . on ( 'data' , function onData ( data ) {
652
- responseData . push ( data )
641
+ responseData . push ( data as Uint8Array )
653
642
} )
654
643
655
644
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
657
645
let responseBody = Buffer . concat ( responseData )
658
646
659
647
// @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 ({
684
672
const isUncaughtError = proxyRes . headers [ 'x-nf-uncaught-error' ] === '1'
685
673
686
674
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
688
676
const decompressedBody = await decompressResponseBody ( responseBody , proxyRes . headers [ 'content-encoding' ] )
689
677
const formattedBody = formatEdgeFunctionError ( decompressedBody , acceptsHtml )
690
678
const errorResponse = acceptsHtml
@@ -777,16 +765,13 @@ const onRequest = async (
777
765
if ( functionMatch ) {
778
766
// Setting an internal header with the function name so that we don't
779
767
// have to match the URL again in the functions server.
780
- /** @type {Record<string, string> } */
781
- const headers = { }
768
+ const headers : Record < string , string > = { }
782
769
783
770
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
785
771
headers [ NFFunctionName ] = functionMatch . func . name
786
772
}
787
773
788
774
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
790
775
headers [ NFFunctionRoute ] = functionMatch . route . pattern
791
776
}
792
777
@@ -815,7 +800,7 @@ const onRequest = async (
815
800
if ( match ) {
816
801
// We don't want to generate an ETag for 3xx redirects.
817
802
// @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
819
804
820
805
return serveRedirect ( { req, res, proxy, imageProxy, match, options, siteInfo, env, functionsRegistry } )
821
806
}
@@ -824,7 +809,7 @@ const onRequest = async (
824
809
// generate an ETag unless we're rendering an error page. The only way for
825
810
// us to know that is by looking at the status code
826
811
// @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
828
813
829
814
const hasFormSubmissionHandler : boolean =
830
815
functionsRegistry && getFormHandler ( { functionsRegistry, logWarning : false } )
0 commit comments