@@ -489,6 +489,102 @@ describe('edge-to-origin - routing - without prefix', () => {
489489 expect ( requestResponse ?. origin ?. custom ?. domainName ) . toBe ( 'abc123.lambda-url.us-east-1.on.aws' ) ;
490490 } ) ;
491491
492+ it ( 'should route `direct` app request with *additional* appName to origin for actual appName' , async ( ) => {
493+ theConfig . replaceHostHeader = true ;
494+ const AppName = 'BatDirect' ;
495+ const SemVer = '1.2.1-beta.1' ;
496+ const AppNameExtraRoute = 'BatDirectExtraRoute' ;
497+
498+ const app = new Application ( {
499+ AppName,
500+ ExtraAppNames : [ AppNameExtraRoute ] ,
501+ DisplayName : 'Direct Bat App' ,
502+ } ) ;
503+ await app . Save ( dbManager ) ;
504+
505+ const version = new Version ( {
506+ AppName,
507+ SemVer,
508+ Status : 'deployed' ,
509+ Type : 'lambda-url' ,
510+ StartupType : 'direct' ,
511+ URL : 'https://abc123.lambda-url.us-east-1.on.aws/' ,
512+ } ) ;
513+ await version . Save ( dbManager ) ;
514+
515+ const rules = new Rules ( {
516+ AppName,
517+ Version : 0 ,
518+ RuleSet : { default : { SemVer, AttributeName : '' , AttributeValue : '' } } ,
519+ } ) ;
520+ await rules . Save ( dbManager ) ;
521+
522+ // Call the handler
523+ // @ts -expect-error no callback
524+ const response = await handler (
525+ {
526+ Records : [
527+ {
528+ cf : {
529+ config : {
530+ distributionDomainName : 'zyz.cloudfront.net' ,
531+ distributionId : '123' ,
532+ eventType : 'origin-request' ,
533+ requestId : '123' ,
534+ } ,
535+ request : {
536+ headers : {
537+ host : [
538+ {
539+ key : 'Host' ,
540+ value : 'zyz.cloudfront.net' ,
541+ } ,
542+ ] ,
543+ } ,
544+ method : 'GET' ,
545+ querystring : '' ,
546+ clientIp : '1.1.1.1' ,
547+ uri : `/${ AppNameExtraRoute . toLowerCase ( ) } ` ,
548+ origin : {
549+ custom : {
550+ customHeaders : { } ,
551+ domainName : 'zyz.cloudfront.net' ,
552+ keepaliveTimeout : 5 ,
553+ path : '' ,
554+ port : 443 ,
555+ protocol : 'https' ,
556+ readTimeout : 30 ,
557+ sslProtocols : [ 'TLSv1.2' ] ,
558+ } ,
559+ } ,
560+ } ,
561+ } ,
562+ } ,
563+ ] ,
564+ } as lambda . CloudFrontRequestEvent ,
565+ { } as lambda . Context ,
566+ ) ;
567+
568+ const requestResponse = response as lambda . CloudFrontRequest ;
569+ expect ( requestResponse ) . toBeDefined ( ) ;
570+ expect ( requestResponse ) . not . toHaveProperty ( 'status' ) ;
571+ expect ( requestResponse ) . not . toHaveProperty ( 'body' ) ;
572+ expect ( requestResponse ) . toHaveProperty ( 'headers' ) ;
573+ expect ( requestResponse . headers [ 'x-microapps-appname' ] [ 0 ] . key ) . toBe ( 'X-MicroApps-AppName' ) ;
574+ expect ( requestResponse . headers [ 'x-microapps-appname' ] [ 0 ] . value ) . toBe ( AppName . toLowerCase ( ) ) ;
575+ expect ( requestResponse . headers ) . toHaveProperty ( 'x-microapps-semver' ) ;
576+ expect ( requestResponse . headers [ 'x-microapps-semver' ] [ 0 ] . key ) . toBe ( 'X-MicroApps-SemVer' ) ;
577+ expect ( requestResponse . headers [ 'x-microapps-semver' ] [ 0 ] . value ) . toBe ( SemVer ) ;
578+ expect ( requestResponse . headers ) . toHaveProperty ( 'host' ) ;
579+ expect ( requestResponse . headers . host ) . toHaveLength ( 1 ) ;
580+ expect ( requestResponse . headers . host [ 0 ] . key ) . toBe ( 'Host' ) ;
581+ expect ( requestResponse . headers . host [ 0 ] . value ) . toBe ( 'abc123.lambda-url.us-east-1.on.aws' ) ;
582+ expect ( requestResponse ) . toHaveProperty ( 'origin' ) ;
583+ expect ( requestResponse . origin ) . toHaveProperty ( 'custom' ) ;
584+ expect ( requestResponse ?. origin ?. custom ) . toHaveProperty ( 'domainName' ) ;
585+ expect ( requestResponse ?. origin ?. custom ?. domainName ) . toBe ( 'abc123.lambda-url.us-east-1.on.aws' ) ;
586+ } ) ;
587+
492588 describe ( '/_next/data/ requests with no basePath' , ( ) => {
493589 const testCases = [
494590 {
0 commit comments