@fy-stack/app-construct 0.0.145 → 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.
- package/dist/lib/ecs/ecs-server-construct.d.ts +1 -0
- package/dist/lib/ecs/ecs-server-construct.d.ts.map +1 -1
- package/dist/lib/ecs/ecs-server-construct.js +4 -2
- package/dist/lib/shared/next-app-router.d.ts.map +1 -1
- package/dist/lib/shared/next-app-router.js +6 -11
- package/dist/lib/static/apps/static-website-construct.d.ts +11 -2
- package/dist/lib/static/apps/static-website-construct.d.ts.map +1 -1
- package/dist/lib/static/apps/static-website-construct.js +45 -2
- package/package.json +2 -2
|
@@ -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,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SAAS,EAAE,GAAG,IAAI;IAMvC,OAAO,CAAC,YAAY;IA8CpB,gBAAgB;;;;IAuChB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CA+CxC"}
|
|
@@ -21,6 +21,7 @@ class EcsServerConstruct extends constructs_1.Construct {
|
|
|
21
21
|
props;
|
|
22
22
|
apps = {};
|
|
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
|
-
|
|
42
|
+
this.service = new ecs.FargateService(this, 'ServerService', {
|
|
42
43
|
cluster,
|
|
43
44
|
taskDefinition: this.definition,
|
|
44
45
|
capacityProviderStrategies: [{ capacityProvider: 'FARGATE', weight: 1 }],
|
|
@@ -52,7 +53,8 @@ class EcsServerConstruct extends constructs_1.Construct {
|
|
|
52
53
|
propagateTags: ecs.PropagatedTagSource.SERVICE,
|
|
53
54
|
...serverProps,
|
|
54
55
|
});
|
|
55
|
-
|
|
56
|
+
this.service.connections.securityGroups[0].securityGroupId;
|
|
57
|
+
const serverOrigin = (port, containerName, appPath, healthPath) => this.serverOrigin(this.service, port, containerName, appPath, healthPath);
|
|
56
58
|
serverOrigin.bind(this);
|
|
57
59
|
Object.assign(this.apps, Object.fromEntries(Object.entries(apps).map(([key, app]) => {
|
|
58
60
|
const AppTypeConstruct = AppBuilds[app.type];
|
|
@@ -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;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;;
|
|
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"}
|
|
@@ -46,17 +46,17 @@ function staticDeployment(app, output) {
|
|
|
46
46
|
}
|
|
47
47
|
function cloudfrontBehaviours(app, staticBucket, serverOrigin, basePath, files) {
|
|
48
48
|
if (basePath) {
|
|
49
|
-
|
|
49
|
+
const strippedBasePath = basePath.replace(/^\/+|\/+$/g, '');
|
|
50
50
|
new s3Deploy.BucketDeployment(app, `${basePath}StaticDeployment`, {
|
|
51
51
|
destinationBucket: staticBucket,
|
|
52
52
|
sources: [files.staticFiles],
|
|
53
|
-
destinationKeyPrefix: `${
|
|
53
|
+
destinationKeyPrefix: `${strippedBasePath}/_next/static/`,
|
|
54
54
|
retainOnDelete: false,
|
|
55
55
|
});
|
|
56
56
|
new s3Deploy.BucketDeployment(app, `${basePath}PublicDeployment`, {
|
|
57
57
|
destinationBucket: staticBucket,
|
|
58
58
|
sources: [files.publicFiles],
|
|
59
|
-
destinationKeyPrefix:
|
|
59
|
+
destinationKeyPrefix: `${strippedBasePath}/`,
|
|
60
60
|
retainOnDelete: false,
|
|
61
61
|
});
|
|
62
62
|
}
|
|
@@ -86,17 +86,12 @@ function cloudfrontBehaviours(app, staticBucket, serverOrigin, basePath, files)
|
|
|
86
86
|
.CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT_AND_SECURITY_HEADERS,
|
|
87
87
|
};
|
|
88
88
|
return {
|
|
89
|
-
[`${basePath}/_next/image`]: {
|
|
90
|
-
...appBehaviour,
|
|
89
|
+
[`${basePath}/_next/image`]: Object.assign({}, appBehaviour, {
|
|
91
90
|
cachePolicy: imageCachePolicy,
|
|
92
91
|
allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD,
|
|
93
|
-
},
|
|
92
|
+
}),
|
|
94
93
|
[`${basePath}/_next/*`]: staticBehavior,
|
|
95
|
-
[`${basePath}
|
|
96
|
-
[`${basePath}/*.png`]: staticBehavior,
|
|
97
|
-
[`${basePath}/*.svg`]: staticBehavior,
|
|
98
|
-
[`${basePath}/*.jpg`]: staticBehavior,
|
|
99
|
-
[`${basePath}/*.jpeg`]: staticBehavior,
|
|
94
|
+
[`${basePath}/*.*`]: staticBehavior,
|
|
100
95
|
[`${basePath}/*`]: appBehaviour,
|
|
101
96
|
};
|
|
102
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<{
|
|
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): {
|
|
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
|
|
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
|
|
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}
|
|
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.
|
|
3
|
+
"version": "0.0.146",
|
|
4
4
|
"repository": "https://github.com/festusyuma/fy-stack",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@fy-stack/types": "0.0.
|
|
6
|
+
"@fy-stack/types": "0.0.146",
|
|
7
7
|
"tslib": "^2.3.0",
|
|
8
8
|
"zod": "^3.24.1"
|
|
9
9
|
},
|