@@ -925,4 +925,124 @@ describe('[proxy] Handler', () => {
925925 } ,
926926 TIMEOUT
927927 ) ;
928+
929+ const staticFileRoutingProbes = [
930+ // ['/en/dynamic/hello', '/en/dynamic/[slug]'],
931+ // ['/en-US/dynamic/hello', '/en-US/dynamic/[slug]'],
932+ // ['/fr-BE/dynamic/hello', '/fr-BE/dynamic/[slug]'],
933+ // ['/fr/dynamic/hello', '/fr/dynamic/[slug]'],
934+ // ['/nl-BE/dynamic/hello', '/nl-BE/dynamic/[slug]'],
935+ // ['/nl-NL/dynamic/hello', '/nl-NL/dynamic/[slug]'],
936+ // ['/nl/dynamic/hello', '/nl/dynamic/[slug]'],
937+ [ '/hello.txt' , '/hello.txt' ] ,
938+ ] ;
939+ test . each ( staticFileRoutingProbes ) (
940+ 'i18n: Correct static file routing %s -> %s' ,
941+ async ( requestPath , targetPath ) => {
942+ const proxyConfig : ProxyConfig = {
943+ staticRoutes : [
944+ '/en-US/dynamic/[slug]' ,
945+ '/en/dynamic/[slug]' ,
946+ '/fr-BE/dynamic/[slug]' ,
947+ '/fr/dynamic/[slug]' ,
948+ '/nl-BE/dynamic/[slug]' ,
949+ '/nl-NL/dynamic/[slug]' ,
950+ '/nl/dynamic/[slug]' ,
951+ '/hello.txt' ,
952+ ] ,
953+ lambdaRoutes : [ ] ,
954+ routes : [
955+ {
956+ src :
957+ '^/(?!(?:_next/.*|en\\-US|nl\\-NL|nl\\-BE|nl|fr\\-BE|fr|en)(?:/.*|$))(.*)$' ,
958+ dest : '$wildcard/$1' ,
959+ continue : true ,
960+ } ,
961+
962+ {
963+ handle : 'filesystem' ,
964+ } ,
965+
966+ {
967+ handle : 'resource' ,
968+ } ,
969+
970+ {
971+ handle : 'miss' ,
972+ } ,
973+ {
974+ handle : 'rewrite' ,
975+ } ,
976+ {
977+ src :
978+ '^[/]?(?<nextLocale>en\\-US|nl\\-NL|nl\\-BE|nl|fr\\-BE|fr|en)?/dynamic/(?<slug>[^/]+?)(?:/)?$' ,
979+ dest : '/$nextLocale/dynamic/[slug]?slug=$slug' ,
980+ check : true ,
981+ } ,
982+ ] ,
983+ prerenders : { } ,
984+ } ;
985+
986+ // Prepare configServer
987+ configServer . proxyConfig = proxyConfig ;
988+
989+ // Origin Request
990+ // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html#example-origin-request
991+ const event : CloudFrontRequestEvent = {
992+ Records : [
993+ {
994+ cf : {
995+ config : {
996+ distributionDomainName : 'd111111abcdef8.cloudfront.net' ,
997+ distributionId : 'EDFDVBD6EXAMPLE' ,
998+ eventType : 'origin-request' ,
999+ requestId :
1000+ '4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==' ,
1001+ } ,
1002+ request : {
1003+ clientIp : '203.0.113.178' ,
1004+ headers : { } ,
1005+ method : 'GET' ,
1006+ origin : {
1007+ s3 : {
1008+ customHeaders : {
1009+ 'x-env-config-endpoint' : [
1010+ {
1011+ key : 'x-env-config-endpoint' ,
1012+ value : configEndpoint ,
1013+ } ,
1014+ ] ,
1015+ 'x-env-api-endpoint' : [
1016+ {
1017+ key : 'x-env-api-endpoint' ,
1018+ value : 'example.localhost' ,
1019+ } ,
1020+ ] ,
1021+ } ,
1022+ region : 'us-east-1' ,
1023+ authMethod : 'origin-access-identity' ,
1024+ domainName : 's3.localhost' ,
1025+ path : '' ,
1026+ } ,
1027+ } ,
1028+ querystring : '' ,
1029+ uri : requestPath ,
1030+ } ,
1031+ } ,
1032+ } ,
1033+ ] ,
1034+ } ;
1035+
1036+ const result = ( await handler ( event ) ) as CloudFrontRequest ;
1037+
1038+ expect ( result . origin ?. s3 ) . toEqual (
1039+ expect . objectContaining ( {
1040+ domainName : 's3.localhost' ,
1041+ path : '' ,
1042+ } )
1043+ ) ;
1044+ expect ( result . uri ) . toBe ( targetPath ) ;
1045+ } ,
1046+ TIMEOUT
1047+ ) ;
9281048} ) ;
0 commit comments