@@ -29,19 +29,17 @@ export function createIPXHandler ({
29
29
basePath = `${ basePath } /`
30
30
}
31
31
const handler : Handler = async ( event , _context ) => {
32
- const host = event . headers . host
33
- const protocol = event . headers [ 'x-forwarded-proto' ] === 'https' ? 'https' : 'http'
34
32
let domains = ( opts as IPXOptions ) . domains || [ ]
35
33
const remoteURLPatterns = remotePatterns || [ ]
36
34
const requestEtag = event . headers [ 'if-none-match' ]
37
- const url = event . path . replace ( basePath , '' )
35
+ const eventPath = event . path . replace ( basePath , '' )
38
36
39
37
// eslint-disable-next-line prefer-const
40
- let [ modifiers = '_' , ...segments ] = url . split ( '/' )
38
+ let [ modifiers = '_' , ...segments ] = eventPath . split ( '/' )
41
39
let id = decodeURIComponent ( segments . join ( '/' ) )
42
40
43
41
if ( propsEncoding === 'base64' ) {
44
- const params = decodeBase64Params ( url )
42
+ const params = decodeBase64Params ( eventPath )
45
43
if ( params . error ) {
46
44
return {
47
45
statusCode : 400 ,
@@ -53,9 +51,11 @@ export function createIPXHandler ({
53
51
}
54
52
55
53
const requestHeaders : Record < string , string > = { }
56
- const isLocal = ! id . startsWith ( 'http' )
54
+ const isLocal = ! id . startsWith ( 'http://' ) && ! id . startsWith ( 'https:// ')
57
55
if ( isLocal ) {
58
- id = `${ protocol } ://${ host } ${ id . startsWith ( '/' ) ? '' : '/' } ${ id } `
56
+ const url = new URL ( event . rawUrl )
57
+ url . pathname = id
58
+ id = url . toString ( )
59
59
if ( event . headers . cookie ) {
60
60
requestHeaders . cookie = event . headers . cookie
61
61
}
0 commit comments