@fy-stack/app-construct 0.0.144 → 0.0.146

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,7 @@ export declare class NextAppRouterConstruct extends Construct implements AppCons
11
11
  container: ecs.ContainerDefinition;
12
12
  queue: sqs.Queue | undefined;
13
13
  private readonly static;
14
+ private readonly files;
14
15
  constructor(scope: Construct, id: string, props: NextAppRouterProps);
15
16
  cloudfront(path: string): Record<string, cloudfront.BehaviorOptions>;
16
17
  cloudfrontPolicy(distributionId: string): void;
@@ -1 +1 @@
1
- {"version":3,"file":"next-app-router-construct.d.ts","sourceRoot":"","sources":["../../../../src/lib/ecs/apps/next-app-router-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAE3C,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AASvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEvD,KAAK,kBAAkB,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AAEjD,qBAAa,sBAAuB,SAAQ,SAAU,YAAW,YAAY;IAMjC,OAAO,CAAC,KAAK;IALhD,SAAS,EAAE,GAAG,CAAC,mBAAmB,CAAC;IACnC,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC;IAEpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;gBAEvB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAU,KAAK,EAAE,kBAAkB;IAe3E,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,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E,MAAM;IAIvC,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAI3C,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAO7C,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;CAG7B"}
@@ -10,17 +10,20 @@ class NextAppRouterConstruct extends constructs_1.Construct {
10
10
  container;
11
11
  queue;
12
12
  static;
13
+ files;
13
14
  constructor(scope, id, props) {
14
15
  super(scope, id);
15
16
  this.props = props;
16
- this.static = (0, next_app_router_1.staticDeployment)(this, props.output);
17
+ const deployment = (0, next_app_router_1.staticDeployment)(this, props.output);
18
+ this.static = deployment.staticBucket;
19
+ this.files = deployment.files;
17
20
  this.container = (0, taskDefinitionImage_1.taskDefinitionImage)(`${props.appName}AppContainer`, {
18
21
  taskDefinition: props.taskDefinition,
19
22
  port: props.port,
20
23
  env: props.env,
21
24
  output: props.output,
22
25
  container: props.container,
23
- environmentPath: props.environmentPath
26
+ environmentPath: props.environmentPath,
24
27
  });
25
28
  }
26
29
  cloudfront(path) {
@@ -28,10 +31,7 @@ class NextAppRouterConstruct extends constructs_1.Construct {
28
31
  if (!origin)
29
32
  throw new Error('No server origin');
30
33
  this.container.addEnvironment('BASE_PATH', basePath);
31
- return {
32
- ...(0, next_app_router_1.serverCloudfrontBehaviour)(this, origin, path),
33
- ...(0, next_app_router_1.staticCloudfrontBehaviour)(this.static, path),
34
- };
34
+ return (0, next_app_router_1.cloudfrontBehaviours)(this, this.static, origin, path, this.files);
35
35
  }
36
36
  cloudfrontPolicy(distributionId) {
37
37
  throw new Error(`cloudfrontPolicy not supported for ${this}`);
@@ -14,6 +14,7 @@ export declare class EcsServerConstruct extends Construct implements Grant {
14
14
  private props;
15
15
  apps: Record<string, AppConstruct>;
16
16
  definition: ecs.TaskDefinition;
17
+ service: ecs.BaseService;
17
18
  loadBalancer?: {
18
19
  alb: elbV2.IApplicationLoadBalancer;
19
20
  listener: elbV2.IApplicationListener;
@@ -1 +1 @@
1
- {"version":3,"file":"ecs-server-construct.d.ts","sourceRoot":"","sources":["../../../src/lib/ecs/ecs-server-construct.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,KAAK,EAAE,SAAS,EAAgB,MAAM,iBAAiB,CAAC;AAG1E,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,KAAK,KAAK,MAAM,wCAAwC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAO1D,KAAK,uBAAuB,GAAG,iBAAiB,CAAC,QAAQ,CAAC,GAAG;IAC3D,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC;CACtB,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,SAAU,YAAW,KAAK;IAY9D,OAAO,CAAC,KAAK;IAXR,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAM;IACxC,UAAU,EAAE,GAAG,CAAC,cAAc,CAAC;IAE/B,YAAY,CAAC,EAAE;QACpB,GAAG,EAAE,KAAK,CAAC,wBAAwB,CAAC;QACpC,QAAQ,EAAE,KAAK,CAAC,oBAAoB,CAAC;KACtC,CAAC;gBAGA,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,EACF,KAAK,EAAE,uBAAuB;IAqExC,KAAK,CAAC,GAAG,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI;IAMvC,OAAO,CAAC,YAAY;IA8CpB,gBAAgB;;;;IAuChB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CA+CxC"}
1
+ {"version":3,"file":"ecs-server-construct.d.ts","sourceRoot":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ps = {};
23
23
  definition;
24
+ service;
24
25
  loadBalancer;
25
26
  constructor(scope, id, props) {
26
27
  super(scope, id);
@@ -38,7 +39,7 @@ class EcsServerConstruct extends constructs_1.Construct {
38
39
  },
39
40
  ...(definition ?? {}),
40
41
  });
41
- const service = new ecs.FargateService(this, 'ServerService', {
42
+ this.service = new ecs.FargateService(this, 'ServerService', {
42
43
  cluster,
43
44
  taskDefinition: this.definition,
44
45
  capacityProviderStrategies: [{ capacityProvider: 'FARGATE', weight: 1 }],
@@ -49,9 +50,11 @@ class EcsServerConstruct extends constructs_1.Construct {
49
50
  : ec2.SubnetType.PRIVATE_WITH_EGRESS,
50
51
  },
51
52
  securityGroups: [appSecurityGroup],
53
+ propagateTags: ecs.PropagatedTagSource.SERVICE,
52
54
  ...serverProps,
53
55
  });
54
- const serverOrigin = (port, containerName, appPath, healthPath) => this.serverOrigin(service, port, containerName, appPath, healthPath);
56
+ this.service.connections.securityGroups[0].securityGroupId;
57
+ const serverOrigin = (port, containerName, appPath, healthPath) => this.serverOrigin(this.service, port, containerName, appPath, healthPath);
55
58
  serverOrigin.bind(this);
56
59
  Object.assign(this.apps, Object.fromEntries(Object.entries(apps).map(([key, app]) => {
57
60
  const AppTypeConstruct = AppBuilds[app.type];
@@ -18,6 +18,7 @@ export declare class NextAppRouterConstruct extends Construct implements AppCons
18
18
  function: lambda.Function;
19
19
  queue: sqs.Queue | undefined;
20
20
  private readonly static;
21
+ private readonly files;
21
22
  constructor(scope: Construct, id: string, props: AppProperties<z.infer<typeof BuildParamsSchema>>);
22
23
  cloudfront(path: string): Record<string, cloudfront.BehaviorOptions>;
23
24
  cloudfrontPolicy(distributionId: string): void;
@@ -1 +1 @@
1
- {"version":3,"file":"next-app-router-construct.d.ts","sourceRoot":"","sources":["../../../../src/lib/lambda/apps/next-app-router-construct.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,EAAE,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,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;;;CAG7B"}
@@ -19,10 +19,13 @@ class NextAppRouterConstruct extends constructs_1.Construct {
19
19
  function;
20
20
  queue;
21
21
  static;
22
+ files;
22
23
  constructor(scope, id, props) {
23
24
  super(scope, id);
24
25
  const region = cdk.Stack.of(this).region;
25
- this.static = (0, next_app_router_1.staticDeployment)(this, props.output);
26
+ const deployment = (0, next_app_router_1.staticDeployment)(this, props.output);
27
+ this.static = deployment.staticBucket;
28
+ this.files = deployment.files;
26
29
  const webAdapterLayer = lambda.LayerVersion.fromLayerVersionArn(this, 'WebAdapterLayer', `arn:aws:lambda:${region}:753240598075:layer:LambdaAdapterLayerX86:25`);
27
30
  const environment = {
28
31
  AWS_LAMBDA_EXEC_WRAPPER: '/opt/bootstrap',
@@ -50,10 +53,7 @@ class NextAppRouterConstruct extends constructs_1.Construct {
50
53
  invokeMode: lambda.InvokeMode.RESPONSE_STREAM,
51
54
  });
52
55
  const serverOrigin = new cloudfrontOrigin.FunctionUrlOrigin(webUrl);
53
- return {
54
- ...(0, next_app_router_1.serverCloudfrontBehaviour)(this, serverOrigin, path),
55
- ...(0, next_app_router_1.staticCloudfrontBehaviour)(this.static, path),
56
- };
56
+ return (0, next_app_router_1.cloudfrontBehaviours)(this, this.static, serverOrigin, path, this.files);
57
57
  }
58
58
  cloudfrontPolicy(distributionId) {
59
59
  throw new Error(`cloudfrontPolicy not supported for ${this}`);
@@ -1,12 +1,20 @@
1
1
  import * as cdk from 'aws-cdk-lib';
2
2
  import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
3
3
  import * as s3 from 'aws-cdk-lib/aws-s3';
4
+ import * as s3Deploy from 'aws-cdk-lib/aws-s3-deployment';
4
5
  import { Construct } from 'constructs';
5
- export declare function staticDeployment(app: Construct, output: string): cdk.aws_s3.Bucket;
6
- export declare function staticCloudfrontBehaviour(staticBucket: s3.Bucket, basePath: string): {
7
- [x: string]: cdk.aws_cloudfront.BehaviorOptions;
6
+ export type AppFile = {
7
+ staticFiles: s3Deploy.ISource;
8
+ publicFiles: s3Deploy.ISource;
9
+ };
10
+ export declare function staticDeployment(app: Construct, output: string): {
11
+ staticBucket: cdk.aws_s3.Bucket;
12
+ files: {
13
+ staticFiles: cdk.aws_s3_deployment.ISource;
14
+ publicFiles: cdk.aws_s3_deployment.ISource;
15
+ };
8
16
  };
9
- export declare function serverCloudfrontBehaviour(app: Construct, serverOrigin: cloudfront.IOrigin, basePath: string): {
17
+ export declare function cloudfrontBehaviours(app: Construct, staticBucket: s3.Bucket, serverOrigin: cloudfront.IOrigin, basePath: string, files: AppFile): {
10
18
  [x: string]: cdk.aws_cloudfront.BehaviorOptions;
11
19
  };
12
20
  //# sourceMappingURL=next-app-router.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"next-app-router.d.ts","sourceRoot":"","sources":["../../../src/lib/shared/next-app-router.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AACnC,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAEzD,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,qBAgC9D;AAED,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,EAAE,CAAC,MAAM,EACvB,QAAQ,EAAE,MAAM;;EAqBjB;AAED,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,SAAS,EACd,YAAY,EAAE,UAAU,CAAC,OAAO,EAChC,QAAQ,EAAE,MAAM;;EA6BjB"}
1
+ {"version":3,"file":"next-app-router.d.ts","sourceRoot":"","sources":["../../../src/lib/shared/next-app-router.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AACnC,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAEzD,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,MAAM,OAAO,GAAG;IACpB,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC;IAC9B,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC;CAC/B,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM;;;;;;EAsC9D;AAED,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,SAAS,EACd,YAAY,EAAE,EAAE,CAAC,MAAM,EACvB,YAAY,EAAE,UAAU,CAAC,OAAO,EAChC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,OAAO;;EA2Df"}
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.staticDeployment = staticDeployment;
4
- exports.staticCloudfrontBehaviour = staticCloudfrontBehaviour;
5
- exports.serverCloudfrontBehaviour = serverCloudfrontBehaviour;
4
+ exports.cloudfrontBehaviours = cloudfrontBehaviours;
6
5
  const tslib_1 = require("tslib");
7
6
  const node_path_1 = tslib_1.__importDefault(require("node:path"));
8
7
  const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
@@ -26,21 +25,41 @@ function staticDeployment(app, output) {
26
25
  },
27
26
  ],
28
27
  });
28
+ const staticFiles = s3Deploy.Source.asset(node_path_1.default.join(output, '/.next/static'));
29
+ const publicFiles = s3Deploy.Source.asset(node_path_1.default.join(output, '/public'));
29
30
  new s3Deploy.BucketDeployment(app, `StaticDeployment`, {
30
31
  destinationBucket: staticBucket,
31
- sources: [s3Deploy.Source.asset(node_path_1.default.join(output, '/.next/static'))],
32
+ sources: [staticFiles],
32
33
  destinationKeyPrefix: '_next/static',
33
34
  retainOnDelete: false,
34
35
  });
35
36
  new s3Deploy.BucketDeployment(app, `PublicDeployment`, {
36
37
  destinationBucket: staticBucket,
37
- sources: [s3Deploy.Source.asset(node_path_1.default.join(output, '/public'))],
38
+ sources: [publicFiles],
38
39
  destinationKeyPrefix: '',
39
40
  retainOnDelete: false,
40
41
  });
41
- return staticBucket;
42
+ return {
43
+ staticBucket,
44
+ files: { staticFiles, publicFiles },
45
+ };
42
46
  }
43
- function staticCloudfrontBehaviour(staticBucket, basePath) {
47
+ function cloudfrontBehaviours(app, staticBucket, serverOrigin, basePath, files) {
48
+ if (basePath) {
49
+ const strippedBasePath = basePath.replace(/^\/+|\/+$/g, '');
50
+ new s3Deploy.BucketDeployment(app, `${basePath}StaticDeployment`, {
51
+ destinationBucket: staticBucket,
52
+ sources: [files.staticFiles],
53
+ destinationKeyPrefix: `${strippedBasePath}/_next/static/`,
54
+ retainOnDelete: false,
55
+ });
56
+ new s3Deploy.BucketDeployment(app, `${basePath}PublicDeployment`, {
57
+ destinationBucket: staticBucket,
58
+ sources: [files.publicFiles],
59
+ destinationKeyPrefix: `${strippedBasePath}/`,
60
+ retainOnDelete: false,
61
+ });
62
+ }
44
63
  const staticOrigin = new cloudfrontOrigin.S3StaticWebsiteOrigin(staticBucket);
45
64
  const staticBehavior = {
46
65
  origin: staticOrigin,
@@ -50,16 +69,6 @@ function staticCloudfrontBehaviour(staticBucket, basePath) {
50
69
  compress: true,
51
70
  viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
52
71
  };
53
- return {
54
- [`${basePath}/_next/*`]: staticBehavior,
55
- [`${basePath}/*.ico`]: staticBehavior,
56
- [`${basePath}/*.png`]: staticBehavior,
57
- [`${basePath}/*.svg`]: staticBehavior,
58
- [`${basePath}/*.jpg`]: staticBehavior,
59
- [`${basePath}/*.jpeg`]: staticBehavior,
60
- };
61
- }
62
- function serverCloudfrontBehaviour(app, serverOrigin, basePath) {
63
72
  const imageCachePolicy = new cloudfront.CachePolicy(app, 'ImagePolicy', {
64
73
  queryStringBehavior: cloudfront.CacheQueryStringBehavior.all(),
65
74
  maxTtl: cdk.Duration.days(365),
@@ -77,11 +86,12 @@ function serverCloudfrontBehaviour(app, serverOrigin, basePath) {
77
86
  .CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT_AND_SECURITY_HEADERS,
78
87
  };
79
88
  return {
80
- [`${basePath}/*`]: appBehaviour,
81
- [`${basePath}/_next/image`]: {
82
- ...appBehaviour,
89
+ [`${basePath}/_next/image`]: Object.assign({}, appBehaviour, {
83
90
  cachePolicy: imageCachePolicy,
84
91
  allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD,
85
- },
92
+ }),
93
+ [`${basePath}/_next/*`]: staticBehavior,
94
+ [`${basePath}/*.*`]: staticBehavior,
95
+ [`${basePath}/*`]: appBehaviour,
86
96
  };
87
97
  }
@@ -3,14 +3,23 @@ import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
3
3
  import { Construct } from 'constructs';
4
4
  import { z } from 'zod';
5
5
  import { AppConstruct, AppProperties } from '../types';
6
- declare const BuildParamsSchema: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
6
+ declare const BuildParamsSchema: z.ZodOptional<z.ZodObject<{
7
+ spa: z.ZodOptional<z.ZodBoolean>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ spa?: boolean | undefined;
10
+ }, {
11
+ spa?: boolean | undefined;
12
+ }>>;
7
13
  export declare class StaticWebsiteConstruct extends Construct implements AppConstruct {
14
+ private props;
8
15
  private readonly static;
9
16
  constructor(scope: Construct, id: string, props: AppProperties<z.infer<typeof BuildParamsSchema>>);
10
17
  cloudfront(path: string): Record<string, cloudfront.BehaviorOptions>;
11
18
  cloudfrontPolicy(distributionId: string): void;
12
19
  api(): Record<string, HttpRouteIntegration>;
13
- static parse(params: unknown): {} | undefined;
20
+ static parse(params: unknown): {
21
+ spa?: boolean | undefined;
22
+ } | undefined;
14
23
  }
15
24
  export {};
16
25
  //# sourceMappingURL=static-website-construct.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"static-website-construct.d.ts","sourceRoot":"","sources":["../../../../src/lib/static/apps/static-website-construct.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAIzD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEvD,QAAA,MAAM,iBAAiB,+DAA0B,CAAC;AAElD,qBAAa,sBAAuB,SAAQ,SAAU,YAAW,YAAY;IAC3E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;gBAGjC,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;IA2BzD,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,eAAe,CAAC;IAmBpE,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAI3C,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;CAG7B"}
1
+ {"version":3,"file":"static-website-construct.d.ts","sourceRoot":"","sources":["../../../../src/lib/static/apps/static-website-construct.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAIzD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEvD,QAAA,MAAM,iBAAiB;;;;;;GAIV,CAAC;AAEd,qBAAa,sBAAuB,SAAQ,SAAU,YAAW,YAAY;IAMzE,OAAO,CAAC,KAAK;IALf,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;gBAGjC,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,EACF,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;IA2BjE,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,eAAe,CAAC;IA2DpE,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAI3C,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;;;CAG7B"}
@@ -9,11 +9,17 @@ const s3 = tslib_1.__importStar(require("aws-cdk-lib/aws-s3"));
9
9
  const s3Deploy = tslib_1.__importStar(require("aws-cdk-lib/aws-s3-deployment"));
10
10
  const constructs_1 = require("constructs");
11
11
  const zod_1 = require("zod");
12
- const BuildParamsSchema = zod_1.z.object({}).optional();
12
+ const BuildParamsSchema = zod_1.z
13
+ .object({
14
+ spa: zod_1.z.boolean().optional(),
15
+ })
16
+ .optional();
13
17
  class StaticWebsiteConstruct extends constructs_1.Construct {
18
+ props;
14
19
  static;
15
20
  constructor(scope, id, props) {
16
21
  super(scope, id);
22
+ this.props = props;
17
23
  this.static = new s3.Bucket(this, `StaticBucket`, {
18
24
  removalPolicy: cdk.RemovalPolicy.DESTROY,
19
25
  autoDeleteObjects: true,
@@ -45,8 +51,45 @@ class StaticWebsiteConstruct extends constructs_1.Construct {
45
51
  compress: true,
46
52
  viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
47
53
  };
54
+ let staticPageBehaviour = Object.assign({}, staticBehavior);
55
+ if (this.props.buildParams?.spa) {
56
+ const spaRewriteFunction = new cloudfront.Function(this, 'SpaRewrite', {
57
+ code: cloudfront.FunctionCode.fromInline(`
58
+ function handler(event) {
59
+ var request = event.request
60
+
61
+ if (!request.uri.endsWith('/')) {
62
+ return {
63
+ statusCode: 301,
64
+ statusDescription: 'Moved Permanently',
65
+ headers: {
66
+ location: {
67
+ value: request.uri + '/'
68
+ }
69
+ }
70
+ }
71
+ }
72
+
73
+ if (request.uri !== "${path || '/'}") {
74
+ request.uri = '/index.html'
75
+ }
76
+
77
+ return request;
78
+ }
79
+ `),
80
+ });
81
+ staticPageBehaviour = Object.assign(staticPageBehaviour, {
82
+ functionAssociations: [
83
+ {
84
+ eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
85
+ function: spaRewriteFunction,
86
+ },
87
+ ],
88
+ });
89
+ }
48
90
  return {
49
- [`${path}/*`]: staticBehavior,
91
+ [`${path}/*.*`]: staticBehavior,
92
+ [`${path}/*`]: staticPageBehaviour,
50
93
  };
51
94
  }
52
95
  cloudfrontPolicy(distributionId) {
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@fy-stack/app-construct",
3
- "version": "0.0.144",
3
+ "version": "0.0.146",
4
4
  "repository": "https://github.com/festusyuma/fy-stack",
5
5
  "dependencies": {
6
- "@fy-stack/types": "0.0.144",
6
+ "@fy-stack/types": "0.0.146",
7
7
  "tslib": "^2.3.0",
8
8
  "zod": "^3.24.1"
9
9
  },