@@ -229,7 +229,7 @@ class Offline {
229
229
skipCacheInvalidation : false ,
230
230
noAuth : false ,
231
231
corsAllowOrigin : '*' ,
232
- corsAllowHeaders : 'accept,content-type,x-api-key' ,
232
+ corsAllowHeaders : 'accept,content-type,x-api-key,authorization ' ,
233
233
corsAllowCredentials : true ,
234
234
apiKey : crypto . createHash ( 'md5' ) . digest ( 'hex' ) ,
235
235
useSeparateProcesses : false ,
@@ -952,35 +952,42 @@ class Offline {
952
952
if ( ! isProxy ) {
953
953
return this . serverlessLog ( `WARNING: Only HTTP_PROXY is supported. Path '${ pathResource } ' is ignored.` ) ;
954
954
}
955
- if ( `${ method } ` . toUpperCase ( ) !== 'GET' ) {
956
- return this . serverlessLog ( `WARNING: ${ method } proxy is not supported. Path '${ pathResource } ' is ignored.` ) ;
957
- }
958
955
if ( ! path ) {
959
956
return this . serverlessLog ( `WARNING: Could not resolve path for '${ methodId } '.` ) ;
960
957
}
961
958
959
+ let fullPath = this . options . prefix + ( pathResource . startsWith ( '/' ) ? pathResource . slice ( 1 ) : pathResource ) ;
960
+ if ( fullPath !== '/' && fullPath . endsWith ( '/' ) ) fullPath = fullPath . slice ( 0 , - 1 ) ;
961
+ fullPath = fullPath . replace ( / \+ } / g, '*}' ) ;
962
+
962
963
const proxyUriOverwrite = resourceRoutesOptions [ methodId ] || { } ;
963
964
const proxyUriInUse = proxyUriOverwrite . Uri || proxyUri ;
964
965
965
966
if ( ! proxyUriInUse ) {
966
967
return this . serverlessLog ( `WARNING: Could not load Proxy Uri for '${ methodId } '` ) ;
967
968
}
969
+ const routeMethod = method === 'ANY' ? '*' : method ;
970
+ const routeConfig = {
971
+ cors : this . options . corsConfig
972
+ }
973
+ if ( routeMethod !== 'HEAD' && routeMethod !== 'GET' ) {
974
+ routeConfig . payload = { parse : false } ;
975
+ }
968
976
969
- this . serverlessLog ( `${ method } ${ pathResource } -> ${ proxyUriInUse } ` ) ;
970
-
977
+ this . serverlessLog ( `${ method } ${ fullPath } -> ${ proxyUriInUse } ` ) ;
971
978
this . server . route ( {
972
- method,
973
- path,
974
- config : { cors : this . options . corsConfig } ,
979
+ method : routeMethod ,
980
+ path : fullPath ,
981
+ config : routeConfig ,
975
982
handler : ( request , reply ) => {
976
983
const params = request . params ;
977
984
let resultUri = proxyUriInUse ;
978
985
979
986
Object . keys ( params ) . forEach ( key => {
980
987
resultUri = resultUri . replace ( `{${ key } }` , params [ key ] ) ;
981
988
} ) ;
982
-
983
- reply . proxy ( { uri : resultUri } ) ;
989
+ this . serverlessLog ( `PROXY ${ request . method } ${ request . url . path } -> ${ resultUri } ` ) ;
990
+ reply . proxy ( { uri : resultUri , passThrough : true } ) ;
984
991
} ,
985
992
} ) ;
986
993
} ) ;
0 commit comments