@@ -396,6 +396,102 @@ describe('edge-to-origin - routing - without prefix', () => {
396396 expect ( requestResponse ?. origin ?. custom ?. domainName ) . toBe ( 'abc123.lambda-url.us-east-1.on.aws' ) ;
397397 } ) ;
398398
399+ it ( 'should route `direct` app request with *additional* appName to origin for actual appName' , async ( ) => {
400+ theConfig . replaceHostHeader = true ;
401+ const AppName = 'BatDirect' ;
402+ const SemVer = '1.2.1-beta.1' ;
403+ const AppNameExtraRoute = 'BatDirectExtraRoute' ;
404+
405+ const app = new Application ( {
406+ AppName,
407+ ExtraAppNames : [ AppNameExtraRoute ] ,
408+ DisplayName : 'Direct Bat App' ,
409+ } ) ;
410+ await app . Save ( dbManager ) ;
411+
412+ const version = new Version ( {
413+ AppName,
414+ SemVer,
415+ Status : 'deployed' ,
416+ Type : 'lambda-url' ,
417+ StartupType : 'direct' ,
418+ URL : 'https://abc123.lambda-url.us-east-1.on.aws/' ,
419+ } ) ;
420+ await version . Save ( dbManager ) ;
421+
422+ const rules = new Rules ( {
423+ AppName,
424+ Version : 0 ,
425+ RuleSet : { default : { SemVer, AttributeName : '' , AttributeValue : '' } } ,
426+ } ) ;
427+ await rules . Save ( dbManager ) ;
428+
429+ // Call the handler
430+ // @ts -expect-error no callback
431+ const response = await handler (
432+ {
433+ Records : [
434+ {
435+ cf : {
436+ config : {
437+ distributionDomainName : 'zyz.cloudfront.net' ,
438+ distributionId : '123' ,
439+ eventType : 'origin-request' ,
440+ requestId : '123' ,
441+ } ,
442+ request : {
443+ headers : {
444+ host : [
445+ {
446+ key : 'Host' ,
447+ value : 'zyz.cloudfront.net' ,
448+ } ,
449+ ] ,
450+ } ,
451+ method : 'GET' ,
452+ querystring : '' ,
453+ clientIp : '1.1.1.1' ,
454+ uri : `/${ AppNameExtraRoute . toLowerCase ( ) } ` ,
455+ origin : {
456+ custom : {
457+ customHeaders : { } ,
458+ domainName : 'zyz.cloudfront.net' ,
459+ keepaliveTimeout : 5 ,
460+ path : '' ,
461+ port : 443 ,
462+ protocol : 'https' ,
463+ readTimeout : 30 ,
464+ sslProtocols : [ 'TLSv1.2' ] ,
465+ } ,
466+ } ,
467+ } ,
468+ } ,
469+ } ,
470+ ] ,
471+ } as lambda . CloudFrontRequestEvent ,
472+ { } as lambda . Context ,
473+ ) ;
474+
475+ const requestResponse = response as lambda . CloudFrontRequest ;
476+ expect ( requestResponse ) . toBeDefined ( ) ;
477+ expect ( requestResponse ) . not . toHaveProperty ( 'status' ) ;
478+ expect ( requestResponse ) . not . toHaveProperty ( 'body' ) ;
479+ expect ( requestResponse ) . toHaveProperty ( 'headers' ) ;
480+ expect ( requestResponse . headers [ 'x-microapps-appname' ] [ 0 ] . key ) . toBe ( 'X-MicroApps-AppName' ) ;
481+ expect ( requestResponse . headers [ 'x-microapps-appname' ] [ 0 ] . value ) . toBe ( AppName . toLowerCase ( ) ) ;
482+ expect ( requestResponse . headers ) . toHaveProperty ( 'x-microapps-semver' ) ;
483+ expect ( requestResponse . headers [ 'x-microapps-semver' ] [ 0 ] . key ) . toBe ( 'X-MicroApps-SemVer' ) ;
484+ expect ( requestResponse . headers [ 'x-microapps-semver' ] [ 0 ] . value ) . toBe ( SemVer ) ;
485+ expect ( requestResponse . headers ) . toHaveProperty ( 'host' ) ;
486+ expect ( requestResponse . headers . host ) . toHaveLength ( 1 ) ;
487+ expect ( requestResponse . headers . host [ 0 ] . key ) . toBe ( 'Host' ) ;
488+ expect ( requestResponse . headers . host [ 0 ] . value ) . toBe ( 'abc123.lambda-url.us-east-1.on.aws' ) ;
489+ expect ( requestResponse ) . toHaveProperty ( 'origin' ) ;
490+ expect ( requestResponse . origin ) . toHaveProperty ( 'custom' ) ;
491+ expect ( requestResponse ?. origin ?. custom ) . toHaveProperty ( 'domainName' ) ;
492+ expect ( requestResponse ?. origin ?. custom ?. domainName ) . toBe ( 'abc123.lambda-url.us-east-1.on.aws' ) ;
493+ } ) ;
494+
399495 describe ( '/_next/data/ requests with no basePath' , ( ) => {
400496 const testCases = [
401497 {
0 commit comments