@gradientedge/cdk-utils 9.3.0 → 9.5.0
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/app/api-destined-function/node_modules/.bin/uuid +2 -2
- package/app/api-destined-function/package.json +3 -3
- package/dist/src/lib/aws/utils/index.js +4 -5
- package/dist/src/lib/cloudflare/construct/index.d.ts +1 -0
- package/dist/src/lib/cloudflare/construct/index.js +1 -0
- package/dist/src/lib/cloudflare/construct/worker-site/index.d.ts +2 -0
- package/dist/src/lib/cloudflare/construct/worker-site/index.js +18 -0
- package/dist/src/lib/cloudflare/construct/worker-site/main.d.ts +43 -0
- package/dist/src/lib/cloudflare/construct/worker-site/main.js +80 -0
- package/dist/src/lib/cloudflare/construct/worker-site/types.d.ts +9 -0
- package/dist/src/lib/cloudflare/construct/worker-site/types.js +2 -0
- package/dist/src/lib/common/utils.d.ts +4 -4
- package/package.json +27 -27
- package/src/lib/cloudflare/construct/index.ts +1 -0
- package/src/lib/cloudflare/construct/worker-site/index.ts +2 -0
- package/src/lib/cloudflare/construct/worker-site/main.ts +94 -0
- package/src/lib/cloudflare/construct/worker-site/types.ts +10 -0
|
@@ -6,9 +6,9 @@ case `uname` in
|
|
|
6
6
|
esac
|
|
7
7
|
|
|
8
8
|
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/cdk-utils/cdk-utils/node_modules/.pnpm/uuid@
|
|
9
|
+
export NODE_PATH="/home/runner/work/cdk-utils/cdk-utils/node_modules/.pnpm/uuid@10.0.0/node_modules/uuid/dist/bin/node_modules:/home/runner/work/cdk-utils/cdk-utils/node_modules/.pnpm/uuid@10.0.0/node_modules/uuid/dist/node_modules:/home/runner/work/cdk-utils/cdk-utils/node_modules/.pnpm/uuid@10.0.0/node_modules/uuid/node_modules:/home/runner/work/cdk-utils/cdk-utils/node_modules/.pnpm/uuid@10.0.0/node_modules:/home/runner/work/cdk-utils/cdk-utils/node_modules/.pnpm/node_modules"
|
|
10
10
|
else
|
|
11
|
-
export NODE_PATH="/home/runner/work/cdk-utils/cdk-utils/node_modules/.pnpm/uuid@
|
|
11
|
+
export NODE_PATH="/home/runner/work/cdk-utils/cdk-utils/node_modules/.pnpm/uuid@10.0.0/node_modules/uuid/dist/bin/node_modules:/home/runner/work/cdk-utils/cdk-utils/node_modules/.pnpm/uuid@10.0.0/node_modules/uuid/dist/node_modules:/home/runner/work/cdk-utils/cdk-utils/node_modules/.pnpm/uuid@10.0.0/node_modules/uuid/node_modules:/home/runner/work/cdk-utils/cdk-utils/node_modules/.pnpm/uuid@10.0.0/node_modules:/home/runner/work/cdk-utils/cdk-utils/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
12
|
fi
|
|
13
13
|
if [ -x "$basedir/node" ]; then
|
|
14
14
|
exec "$basedir/node" "$basedir/../uuid/dist/bin/uuid" "$@"
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"test": "npx jest --ci --runInBand --passWithNoTests"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@types/uuid": "^
|
|
20
|
-
"uuid": "^
|
|
19
|
+
"@types/uuid": "^10.0.0",
|
|
20
|
+
"uuid": "^10.0.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"mkdirp": "^3.0.1",
|
|
24
|
-
"rimraf": "^5.0.
|
|
24
|
+
"rimraf": "^5.0.7"
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -3,7 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.createCfnOutput = createCfnOutput;
|
|
7
|
+
exports.determineCredentials = determineCredentials;
|
|
8
|
+
exports.redirectError = redirectError;
|
|
9
|
+
exports.redirectSuccess = redirectSuccess;
|
|
7
10
|
const credential_providers_1 = require("@aws-sdk/credential-providers");
|
|
8
11
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
9
12
|
const lodash_1 = __importDefault(require("lodash"));
|
|
@@ -28,7 +31,6 @@ function createCfnOutput(id, scope, value, description, overrideId = true) {
|
|
|
28
31
|
}
|
|
29
32
|
return output;
|
|
30
33
|
}
|
|
31
|
-
exports.createCfnOutput = createCfnOutput;
|
|
32
34
|
/**
|
|
33
35
|
*
|
|
34
36
|
*/
|
|
@@ -37,7 +39,6 @@ function determineCredentials() {
|
|
|
37
39
|
return (0, credential_providers_1.fromIni)();
|
|
38
40
|
return (0, credential_providers_1.fromEnv)();
|
|
39
41
|
}
|
|
40
|
-
exports.determineCredentials = determineCredentials;
|
|
41
42
|
/**
|
|
42
43
|
*/
|
|
43
44
|
const defaultResponseObject = {
|
|
@@ -58,7 +59,6 @@ function redirectError(error) {
|
|
|
58
59
|
statusCode: 500,
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
|
-
exports.redirectError = redirectError;
|
|
62
62
|
/**
|
|
63
63
|
* @param message
|
|
64
64
|
*/
|
|
@@ -68,4 +68,3 @@ function redirectSuccess(message) {
|
|
|
68
68
|
statusCode: 200,
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
exports.redirectSuccess = redirectSuccess;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./main"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DataCloudflareZone } from '@cdktf/provider-cloudflare/lib/data-cloudflare-zone';
|
|
2
|
+
import { WorkerScript, WorkerScriptPlainTextBinding, WorkerScriptSecretTextBinding } from '@cdktf/provider-cloudflare/lib/worker-script';
|
|
3
|
+
import { Zone } from '@cdktf/provider-cloudflare/lib/zone';
|
|
4
|
+
import { Construct } from 'constructs';
|
|
5
|
+
import { CommonCloudflareConstruct } from '../../common';
|
|
6
|
+
import { CloudflareWorkerSiteProps } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* @classdesc Provides a construct to create and deploy a cloudflare worker site
|
|
9
|
+
* @example
|
|
10
|
+
* import { CloudflareWorkerSite, CloudflareWorkerSiteProps } '@gradientedge/cdk-utils'
|
|
11
|
+
* import { Construct } from 'constructs'
|
|
12
|
+
*
|
|
13
|
+
* class CustomConstruct extends CloudflareWorkerSite {
|
|
14
|
+
* constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps) {
|
|
15
|
+
* super(parent, id, props)
|
|
16
|
+
* this.props = props
|
|
17
|
+
* this.id = id
|
|
18
|
+
* this.initResources()
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export declare class CloudflareWorkerSite extends CommonCloudflareConstruct {
|
|
23
|
+
props: CloudflareWorkerSiteProps;
|
|
24
|
+
siteZone: DataCloudflareZone | Zone;
|
|
25
|
+
siteWorkerScript: WorkerScript;
|
|
26
|
+
workerPlainTextBindingEnvironmentVariables: WorkerScriptPlainTextBinding[];
|
|
27
|
+
workerSecretTextBindingEnvironmentVariables: WorkerScriptSecretTextBinding[];
|
|
28
|
+
constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps);
|
|
29
|
+
/**
|
|
30
|
+
* @summary Initialise and provision resources
|
|
31
|
+
*/
|
|
32
|
+
protected initResources(): void;
|
|
33
|
+
/**
|
|
34
|
+
* @summary Resolve the zone to use for the worker site
|
|
35
|
+
*/
|
|
36
|
+
protected resolveZone(): void;
|
|
37
|
+
/**
|
|
38
|
+
* @summary Resolve the environment variables to use for the static site
|
|
39
|
+
*/
|
|
40
|
+
protected resolveEnvironmentVariables(): void;
|
|
41
|
+
protected createWorker(): void;
|
|
42
|
+
protected createWorkerDomain(): void;
|
|
43
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CloudflareWorkerSite = void 0;
|
|
4
|
+
const cdktf_1 = require("cdktf");
|
|
5
|
+
const common_1 = require("../../common");
|
|
6
|
+
/**
|
|
7
|
+
* @classdesc Provides a construct to create and deploy a cloudflare worker site
|
|
8
|
+
* @example
|
|
9
|
+
* import { CloudflareWorkerSite, CloudflareWorkerSiteProps } '@gradientedge/cdk-utils'
|
|
10
|
+
* import { Construct } from 'constructs'
|
|
11
|
+
*
|
|
12
|
+
* class CustomConstruct extends CloudflareWorkerSite {
|
|
13
|
+
* constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps) {
|
|
14
|
+
* super(parent, id, props)
|
|
15
|
+
* this.props = props
|
|
16
|
+
* this.id = id
|
|
17
|
+
* this.initResources()
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
21
|
+
class CloudflareWorkerSite extends common_1.CommonCloudflareConstruct {
|
|
22
|
+
/* worker site resources */
|
|
23
|
+
siteZone;
|
|
24
|
+
siteWorkerScript;
|
|
25
|
+
workerPlainTextBindingEnvironmentVariables;
|
|
26
|
+
workerSecretTextBindingEnvironmentVariables;
|
|
27
|
+
constructor(parent, id, props) {
|
|
28
|
+
super(parent, id, props);
|
|
29
|
+
this.props = props;
|
|
30
|
+
this.id = id;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @summary Initialise and provision resources
|
|
34
|
+
*/
|
|
35
|
+
initResources() {
|
|
36
|
+
this.resolveZone();
|
|
37
|
+
this.resolveEnvironmentVariables();
|
|
38
|
+
this.createWorker();
|
|
39
|
+
this.createWorkerDomain();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @summary Resolve the zone to use for the worker site
|
|
43
|
+
*/
|
|
44
|
+
resolveZone() {
|
|
45
|
+
if (this.props.useExistingZone) {
|
|
46
|
+
this.siteZone = this.zoneManager.resolveZone(`${this.id}-zone`, this);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.siteZone = this.zoneManager.createZone(`${this.id}-zone`, this, this.props.siteZone);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @summary Resolve the environment variables to use for the static site
|
|
54
|
+
*/
|
|
55
|
+
resolveEnvironmentVariables() {
|
|
56
|
+
this.props.siteWorkerScript = {
|
|
57
|
+
...this.props.siteWorkerScript,
|
|
58
|
+
plainTextBinding: this.workerPlainTextBindingEnvironmentVariables,
|
|
59
|
+
secretTextBinding: this.workerSecretTextBindingEnvironmentVariables,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
createWorker() {
|
|
63
|
+
const workerContent = new cdktf_1.TerraformAsset(this, `${this.id}-worker-content`, {
|
|
64
|
+
path: this.props.siteWorkerAsset,
|
|
65
|
+
type: cdktf_1.AssetType.FILE,
|
|
66
|
+
});
|
|
67
|
+
this.siteWorkerScript = this.workerManager.createWorkerScript(`${this.id}-worker-script`, this, {
|
|
68
|
+
...this.props.siteWorkerScript,
|
|
69
|
+
content: cdktf_1.Fn.file(workerContent.path),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
createWorkerDomain() {
|
|
73
|
+
this.workerManager.createWorkerDomain(`${this.id}-worker-domain`, this, {
|
|
74
|
+
...this.props.siteWorkerDomain,
|
|
75
|
+
hostname: `${this.props.siteSubDomain}.${this.props.domainName}`,
|
|
76
|
+
service: this.siteWorkerScript.name,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.CloudflareWorkerSite = CloudflareWorkerSite;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CommonCloudflareStackProps } from '../../common';
|
|
2
|
+
import { WorkerDomainProps, WorkerScriptProps, ZoneProps } from '../../services';
|
|
3
|
+
export interface CloudflareWorkerSiteProps extends CommonCloudflareStackProps {
|
|
4
|
+
siteSubDomain: string;
|
|
5
|
+
siteZone: ZoneProps;
|
|
6
|
+
siteWorkerScript: WorkerScriptProps;
|
|
7
|
+
siteWorkerDomain: WorkerDomainProps;
|
|
8
|
+
siteWorkerAsset: string;
|
|
9
|
+
}
|
|
@@ -11,16 +11,16 @@ export declare enum LogLevel {
|
|
|
11
11
|
/**
|
|
12
12
|
* @param stage
|
|
13
13
|
*/
|
|
14
|
-
export declare const isDevStage: (stage: string) =>
|
|
14
|
+
export declare const isDevStage: (stage: string) => stage is "dev";
|
|
15
15
|
/**
|
|
16
16
|
* @param stage
|
|
17
17
|
*/
|
|
18
|
-
export declare const isTestStage: (stage: string) =>
|
|
18
|
+
export declare const isTestStage: (stage: string) => stage is "tst";
|
|
19
19
|
/**
|
|
20
20
|
* @param stage
|
|
21
21
|
*/
|
|
22
|
-
export declare const isUatStage: (stage: string) =>
|
|
22
|
+
export declare const isUatStage: (stage: string) => stage is "uat";
|
|
23
23
|
/**
|
|
24
24
|
* @param stage
|
|
25
25
|
*/
|
|
26
|
-
export declare const isPrdStage: (stage: string) =>
|
|
26
|
+
export declare const isPrdStage: (stage: string) => stage is "prd";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradientedge/cdk-utils",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.5.0",
|
|
4
4
|
"description": "Utilities for AWS CDK provisioning",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -50,62 +50,62 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@aws-sdk/client-secrets-manager": "^3.
|
|
54
|
-
"@aws-sdk/credential-providers": "^3.
|
|
55
|
-
"@aws-sdk/types": "^3.
|
|
56
|
-
"@cdktf/provider-aws": "^19.
|
|
57
|
-
"@cdktf/provider-azurerm": "^12.
|
|
58
|
-
"@cdktf/provider-cloudflare": "^11.
|
|
59
|
-
"@types/lodash": "^4.17.
|
|
60
|
-
"@types/node": "^20.
|
|
61
|
-
"@types/uuid": "^
|
|
53
|
+
"@aws-sdk/client-secrets-manager": "^3.600.0",
|
|
54
|
+
"@aws-sdk/credential-providers": "^3.600.0",
|
|
55
|
+
"@aws-sdk/types": "^3.598.0",
|
|
56
|
+
"@cdktf/provider-aws": "^19.23.0",
|
|
57
|
+
"@cdktf/provider-azurerm": "^12.21.0",
|
|
58
|
+
"@cdktf/provider-cloudflare": "^11.13.0",
|
|
59
|
+
"@types/lodash": "^4.17.5",
|
|
60
|
+
"@types/node": "^20.14.8",
|
|
61
|
+
"@types/uuid": "^10.0.0",
|
|
62
62
|
"app-root-path": "^3.1.0",
|
|
63
|
-
"aws-cdk-lib": "^2.
|
|
63
|
+
"aws-cdk-lib": "^2.147.1",
|
|
64
64
|
"cdktf": "^0.20.7",
|
|
65
|
-
"cdktf-local-exec": "^0.5.
|
|
65
|
+
"cdktf-local-exec": "^0.5.23",
|
|
66
66
|
"constructs": "^10.3.0",
|
|
67
67
|
"lodash": "^4.17.21",
|
|
68
68
|
"moment": "^2.30.1",
|
|
69
69
|
"nconf": "^0.12.1",
|
|
70
70
|
"pluralize": "^8.0.0",
|
|
71
71
|
"ts-node": "^10.9.2",
|
|
72
|
-
"uuid": "^
|
|
72
|
+
"uuid": "^10.0.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@babel/core": "^7.24.
|
|
76
|
-
"@babel/eslint-parser": "^7.24.
|
|
75
|
+
"@babel/core": "^7.24.7",
|
|
76
|
+
"@babel/eslint-parser": "^7.24.7",
|
|
77
77
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
78
78
|
"@types/jest": "^29.5.12",
|
|
79
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
80
|
-
"@typescript-eslint/parser": "^7.
|
|
81
|
-
"aws-cdk": "^2.
|
|
79
|
+
"@typescript-eslint/eslint-plugin": "^7.14.1",
|
|
80
|
+
"@typescript-eslint/parser": "^7.14.1",
|
|
81
|
+
"aws-cdk": "^2.147.1",
|
|
82
82
|
"better-docs": "^2.7.3",
|
|
83
83
|
"codecov": "^3.8.3",
|
|
84
84
|
"commitizen": "^4.3.0",
|
|
85
85
|
"docdash": "^2.0.2",
|
|
86
86
|
"dotenv": "^16.4.5",
|
|
87
|
-
"eslint": "^9.
|
|
87
|
+
"eslint": "^9.5.0",
|
|
88
88
|
"eslint-config-prettier": "^9.1.0",
|
|
89
89
|
"eslint-plugin-import": "^2.29.1",
|
|
90
|
-
"eslint-plugin-jsdoc": "^48.
|
|
90
|
+
"eslint-plugin-jsdoc": "^48.4.0",
|
|
91
91
|
"husky": "^9.0.11",
|
|
92
92
|
"jest": "^29.7.0",
|
|
93
93
|
"jest-extended": "^4.0.2",
|
|
94
94
|
"jest-junit": "^16.0.0",
|
|
95
|
-
"jsdoc": "^4.0.
|
|
95
|
+
"jsdoc": "^4.0.3",
|
|
96
96
|
"jsdoc-babel": "^0.5.0",
|
|
97
97
|
"jsdoc-mermaid": "^1.0.0",
|
|
98
98
|
"jsdoc-plugin-typescript": "^2.2.1",
|
|
99
99
|
"jsdoc-to-markdown": "^8.0.1",
|
|
100
|
-
"prettier": "^3.2
|
|
100
|
+
"prettier": "^3.3.2",
|
|
101
101
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
102
|
-
"rimraf": "^5.0.
|
|
103
|
-
"semantic-release": "^
|
|
102
|
+
"rimraf": "^5.0.7",
|
|
103
|
+
"semantic-release": "^24.0.0",
|
|
104
104
|
"taffydb": "^2.7.3",
|
|
105
|
-
"ts-jest": "^29.1.
|
|
105
|
+
"ts-jest": "^29.1.5",
|
|
106
106
|
"ts-node": "^10.9.2",
|
|
107
|
-
"typescript": "5.
|
|
108
|
-
"yaml": "^2.4.
|
|
107
|
+
"typescript": "5.5.2",
|
|
108
|
+
"yaml": "^2.4.5"
|
|
109
109
|
},
|
|
110
110
|
"optionalDependencies": {
|
|
111
111
|
"prop-types": "^15.8.1",
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { DataCloudflareZone } from '@cdktf/provider-cloudflare/lib/data-cloudflare-zone'
|
|
2
|
+
import {
|
|
3
|
+
WorkerScript,
|
|
4
|
+
WorkerScriptPlainTextBinding,
|
|
5
|
+
WorkerScriptSecretTextBinding,
|
|
6
|
+
} from '@cdktf/provider-cloudflare/lib/worker-script'
|
|
7
|
+
import { Zone } from '@cdktf/provider-cloudflare/lib/zone'
|
|
8
|
+
import { Fn, TerraformAsset, AssetType } from 'cdktf'
|
|
9
|
+
import { Construct } from 'constructs'
|
|
10
|
+
import { CommonCloudflareConstruct } from '../../common'
|
|
11
|
+
import { CloudflareWorkerSiteProps } from './types'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @classdesc Provides a construct to create and deploy a cloudflare worker site
|
|
15
|
+
* @example
|
|
16
|
+
* import { CloudflareWorkerSite, CloudflareWorkerSiteProps } '@gradientedge/cdk-utils'
|
|
17
|
+
* import { Construct } from 'constructs'
|
|
18
|
+
*
|
|
19
|
+
* class CustomConstruct extends CloudflareWorkerSite {
|
|
20
|
+
* constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps) {
|
|
21
|
+
* super(parent, id, props)
|
|
22
|
+
* this.props = props
|
|
23
|
+
* this.id = id
|
|
24
|
+
* this.initResources()
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
*/
|
|
28
|
+
export class CloudflareWorkerSite extends CommonCloudflareConstruct {
|
|
29
|
+
declare props: CloudflareWorkerSiteProps
|
|
30
|
+
|
|
31
|
+
/* worker site resources */
|
|
32
|
+
siteZone: DataCloudflareZone | Zone
|
|
33
|
+
siteWorkerScript: WorkerScript
|
|
34
|
+
workerPlainTextBindingEnvironmentVariables: WorkerScriptPlainTextBinding[]
|
|
35
|
+
workerSecretTextBindingEnvironmentVariables: WorkerScriptSecretTextBinding[]
|
|
36
|
+
|
|
37
|
+
constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps) {
|
|
38
|
+
super(parent, id, props)
|
|
39
|
+
this.props = props
|
|
40
|
+
this.id = id
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @summary Initialise and provision resources
|
|
45
|
+
*/
|
|
46
|
+
protected initResources() {
|
|
47
|
+
this.resolveZone()
|
|
48
|
+
this.resolveEnvironmentVariables()
|
|
49
|
+
this.createWorker()
|
|
50
|
+
this.createWorkerDomain()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @summary Resolve the zone to use for the worker site
|
|
55
|
+
*/
|
|
56
|
+
protected resolveZone() {
|
|
57
|
+
if (this.props.useExistingZone) {
|
|
58
|
+
this.siteZone = this.zoneManager.resolveZone(`${this.id}-zone`, this)
|
|
59
|
+
} else {
|
|
60
|
+
this.siteZone = this.zoneManager.createZone(`${this.id}-zone`, this, this.props.siteZone)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @summary Resolve the environment variables to use for the static site
|
|
66
|
+
*/
|
|
67
|
+
protected resolveEnvironmentVariables() {
|
|
68
|
+
this.props.siteWorkerScript = {
|
|
69
|
+
...this.props.siteWorkerScript,
|
|
70
|
+
plainTextBinding: this.workerPlainTextBindingEnvironmentVariables,
|
|
71
|
+
secretTextBinding: this.workerSecretTextBindingEnvironmentVariables,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
protected createWorker() {
|
|
76
|
+
const workerContent = new TerraformAsset(this, `${this.id}-worker-content`, {
|
|
77
|
+
path: this.props.siteWorkerAsset,
|
|
78
|
+
type: AssetType.FILE,
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
this.siteWorkerScript = this.workerManager.createWorkerScript(`${this.id}-worker-script`, this, {
|
|
82
|
+
...this.props.siteWorkerScript,
|
|
83
|
+
content: Fn.file(workerContent.path),
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
protected createWorkerDomain() {
|
|
88
|
+
this.workerManager.createWorkerDomain(`${this.id}-worker-domain`, this, {
|
|
89
|
+
...this.props.siteWorkerDomain,
|
|
90
|
+
hostname: `${this.props.siteSubDomain}.${this.props.domainName}`,
|
|
91
|
+
service: this.siteWorkerScript.name,
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CommonCloudflareStackProps } from '../../common'
|
|
2
|
+
import { WorkerDomainProps, WorkerScriptProps, RecordProps, ZoneProps } from '../../services'
|
|
3
|
+
|
|
4
|
+
export interface CloudflareWorkerSiteProps extends CommonCloudflareStackProps {
|
|
5
|
+
siteSubDomain: string
|
|
6
|
+
siteZone: ZoneProps
|
|
7
|
+
siteWorkerScript: WorkerScriptProps
|
|
8
|
+
siteWorkerDomain: WorkerDomainProps
|
|
9
|
+
siteWorkerAsset: string
|
|
10
|
+
}
|