@webiny/pulumi-aws 5.25.0-beta.6 → 5.25.1-beta.1
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/apps/admin/AdminApp.d.ts +14 -0
- package/apps/admin/AdminApp.js +134 -0
- package/apps/admin/AdminApp.js.map +1 -0
- package/apps/admin/AdminUpload.d.ts +6 -0
- package/apps/admin/AdminUpload.js +50 -0
- package/apps/admin/AdminUpload.js.map +1 -0
- package/apps/api/ApiApp.d.ts +66 -0
- package/apps/api/ApiApp.js +223 -0
- package/apps/api/ApiApp.js.map +1 -0
- package/apps/api/ApiApwScheduler.d.ts +23 -0
- package/apps/api/ApiApwScheduler.js +240 -0
- package/apps/api/ApiApwScheduler.js.map +1 -0
- package/apps/api/ApiCloudfront.d.ts +4 -0
- package/apps/api/ApiCloudfront.js +103 -0
- package/apps/api/ApiCloudfront.js.map +1 -0
- package/apps/api/ApiFileManager.d.ts +18 -0
- package/apps/api/ApiFileManager.js +168 -0
- package/apps/api/ApiFileManager.js.map +1 -0
- package/apps/api/ApiGateway.d.ts +19 -0
- package/apps/api/ApiGateway.js +90 -0
- package/apps/api/ApiGateway.js.map +1 -0
- package/apps/api/ApiGraphql.d.ts +27 -0
- package/apps/api/ApiGraphql.js +128 -0
- package/apps/api/ApiGraphql.js.map +1 -0
- package/apps/api/ApiHeadlessCMS.d.ts +18 -0
- package/apps/api/ApiHeadlessCMS.js +90 -0
- package/apps/api/ApiHeadlessCMS.js.map +1 -0
- package/apps/api/ApiLambdaUtils.d.ts +11 -0
- package/apps/api/ApiLambdaUtils.js +45 -0
- package/apps/api/ApiLambdaUtils.js.map +1 -0
- package/apps/api/ApiPageBuilder.d.ts +40 -0
- package/apps/api/ApiPageBuilder.js +289 -0
- package/apps/api/ApiPageBuilder.js.map +1 -0
- package/apps/api/ApiPrerendering.d.ts +24 -0
- package/apps/api/ApiPrerendering.js +200 -0
- package/apps/api/ApiPrerendering.js.map +1 -0
- package/apps/api/ApiVpc.d.ts +10 -0
- package/apps/api/ApiVpc.js +129 -0
- package/apps/api/ApiVpc.js.map +1 -0
- package/apps/api/index.d.ts +8 -0
- package/apps/api/index.js +109 -0
- package/apps/api/index.js.map +1 -0
- package/apps/awsUtils.d.ts +3 -0
- package/apps/awsUtils.js +25 -0
- package/apps/awsUtils.js.map +1 -0
- package/apps/createAppBucket.d.ts +13 -0
- package/apps/createAppBucket.js +107 -0
- package/apps/createAppBucket.js.map +1 -0
- package/apps/customDomain.d.ts +9 -0
- package/apps/customDomain.js +14 -0
- package/apps/customDomain.js.map +1 -0
- package/apps/getStorageOutput.d.ts +13 -0
- package/apps/getStorageOutput.js +29 -0
- package/apps/getStorageOutput.js.map +1 -0
- package/apps/index.d.ts +5 -0
- package/apps/index.js +72 -0
- package/apps/index.js.map +1 -0
- package/apps/storage/StorageApp.d.ts +16 -0
- package/apps/storage/StorageApp.js +90 -0
- package/apps/storage/StorageApp.js.map +1 -0
- package/apps/storage/StorageCognito.d.ts +11 -0
- package/apps/storage/StorageCognito.js +102 -0
- package/apps/storage/StorageCognito.js.map +1 -0
- package/apps/storage/StorageDynamo.d.ts +6 -0
- package/apps/storage/StorageDynamo.js +53 -0
- package/apps/storage/StorageDynamo.js.map +1 -0
- package/apps/storage/StorageFileManager.d.ts +6 -0
- package/apps/storage/StorageFileManager.js +40 -0
- package/apps/storage/StorageFileManager.js.map +1 -0
- package/apps/storage/index.d.ts +4 -0
- package/apps/storage/index.js +57 -0
- package/apps/storage/index.js.map +1 -0
- package/apps/website/WebsiteApp.d.ts +22 -0
- package/apps/website/WebsiteApp.js +206 -0
- package/apps/website/WebsiteApp.js.map +1 -0
- package/apps/website/WebsiteHookRender.d.ts +1 -0
- package/apps/website/WebsiteHookRender.js +65 -0
- package/apps/website/WebsiteHookRender.js.map +1 -0
- package/apps/website/WebsiteHookUpdatePbSettings.d.ts +5 -0
- package/apps/website/WebsiteHookUpdatePbSettings.js +80 -0
- package/apps/website/WebsiteHookUpdatePbSettings.js.map +1 -0
- package/apps/website/WebsiteHookUpload.d.ts +1 -0
- package/apps/website/WebsiteHookUpload.js +65 -0
- package/apps/website/WebsiteHookUpload.js.map +1 -0
- package/components/tenantRouter/functions/origin/request.js +54 -8
- package/components/tenantRouter/functions/origin/request.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +18 -1
- package/index.js.map +1 -1
- package/package.json +10 -6
- package/types.d.ts +2 -0
- package/types.js +5 -0
- package/types.js.map +1 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.WebsiteApp = void 0;
|
|
9
|
+
exports.createWebsiteApp = createWebsiteApp;
|
|
10
|
+
|
|
11
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
+
|
|
13
|
+
var aws = _interopRequireWildcard(require("@pulumi/aws"));
|
|
14
|
+
|
|
15
|
+
var _pulumiSdk = require("@webiny/pulumi-sdk");
|
|
16
|
+
|
|
17
|
+
var _createAppBucket = require("../createAppBucket");
|
|
18
|
+
|
|
19
|
+
var _WebsiteHookUpload = require("./WebsiteHookUpload");
|
|
20
|
+
|
|
21
|
+
var _WebsiteHookRender = require("./WebsiteHookRender");
|
|
22
|
+
|
|
23
|
+
var _WebsiteHookUpdatePbSettings = require("./WebsiteHookUpdatePbSettings");
|
|
24
|
+
|
|
25
|
+
var _customDomain = require("../customDomain");
|
|
26
|
+
|
|
27
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
28
|
+
|
|
29
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
30
|
+
|
|
31
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
32
|
+
|
|
33
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
34
|
+
|
|
35
|
+
const WebsiteApp = (0, _pulumiSdk.defineApp)({
|
|
36
|
+
name: "Website",
|
|
37
|
+
|
|
38
|
+
config(app, config) {
|
|
39
|
+
var _config$domain;
|
|
40
|
+
|
|
41
|
+
const appBucket = (0, _createAppBucket.createPublicAppBucket)(app, "app");
|
|
42
|
+
const appCloudfront = app.addResource(aws.cloudfront.Distribution, {
|
|
43
|
+
name: "app",
|
|
44
|
+
config: {
|
|
45
|
+
enabled: true,
|
|
46
|
+
waitForDeployment: true,
|
|
47
|
+
origins: [appBucket.origin],
|
|
48
|
+
defaultRootObject: "index.html",
|
|
49
|
+
defaultCacheBehavior: {
|
|
50
|
+
compress: true,
|
|
51
|
+
targetOriginId: appBucket.origin.originId,
|
|
52
|
+
viewerProtocolPolicy: "redirect-to-https",
|
|
53
|
+
allowedMethods: ["GET", "HEAD", "OPTIONS"],
|
|
54
|
+
cachedMethods: ["GET", "HEAD", "OPTIONS"],
|
|
55
|
+
forwardedValues: {
|
|
56
|
+
cookies: {
|
|
57
|
+
forward: "none"
|
|
58
|
+
},
|
|
59
|
+
queryString: false
|
|
60
|
+
},
|
|
61
|
+
// MinTTL <= DefaultTTL <= MaxTTL
|
|
62
|
+
minTtl: 0,
|
|
63
|
+
defaultTtl: 0,
|
|
64
|
+
maxTtl: 0
|
|
65
|
+
},
|
|
66
|
+
priceClass: "PriceClass_100",
|
|
67
|
+
customErrorResponses: [{
|
|
68
|
+
errorCode: 404,
|
|
69
|
+
responseCode: 404,
|
|
70
|
+
responsePagePath: "/index.html"
|
|
71
|
+
}],
|
|
72
|
+
restrictions: {
|
|
73
|
+
geoRestriction: {
|
|
74
|
+
restrictionType: "none"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
viewerCertificate: {
|
|
78
|
+
cloudfrontDefaultCertificate: true
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
const deliveryBucket = (0, _createAppBucket.createPublicAppBucket)(app, "delivery");
|
|
83
|
+
const deliveryCloudfront = app.addResource(aws.cloudfront.Distribution, {
|
|
84
|
+
name: "delivery",
|
|
85
|
+
config: {
|
|
86
|
+
enabled: true,
|
|
87
|
+
waitForDeployment: true,
|
|
88
|
+
origins: [deliveryBucket.origin, appBucket.origin],
|
|
89
|
+
defaultRootObject: "index.html",
|
|
90
|
+
defaultCacheBehavior: {
|
|
91
|
+
compress: true,
|
|
92
|
+
targetOriginId: deliveryBucket.origin.originId,
|
|
93
|
+
viewerProtocolPolicy: "redirect-to-https",
|
|
94
|
+
allowedMethods: ["GET", "HEAD", "OPTIONS"],
|
|
95
|
+
cachedMethods: ["GET", "HEAD", "OPTIONS"],
|
|
96
|
+
originRequestPolicyId: "",
|
|
97
|
+
forwardedValues: {
|
|
98
|
+
cookies: {
|
|
99
|
+
forward: "none"
|
|
100
|
+
},
|
|
101
|
+
queryString: true
|
|
102
|
+
},
|
|
103
|
+
// MinTTL <= DefaultTTL <= MaxTTL
|
|
104
|
+
minTtl: 0,
|
|
105
|
+
defaultTtl: 30,
|
|
106
|
+
maxTtl: 30
|
|
107
|
+
},
|
|
108
|
+
orderedCacheBehaviors: [{
|
|
109
|
+
compress: true,
|
|
110
|
+
allowedMethods: ["GET", "HEAD", "OPTIONS"],
|
|
111
|
+
cachedMethods: ["GET", "HEAD", "OPTIONS"],
|
|
112
|
+
forwardedValues: {
|
|
113
|
+
cookies: {
|
|
114
|
+
forward: "none"
|
|
115
|
+
},
|
|
116
|
+
headers: [],
|
|
117
|
+
queryString: false
|
|
118
|
+
},
|
|
119
|
+
pathPattern: "/static/*",
|
|
120
|
+
viewerProtocolPolicy: "allow-all",
|
|
121
|
+
targetOriginId: appBucket.origin.originId,
|
|
122
|
+
// MinTTL <= DefaultTTL <= MaxTTL
|
|
123
|
+
minTtl: 0,
|
|
124
|
+
defaultTtl: 2592000,
|
|
125
|
+
// 30 days
|
|
126
|
+
maxTtl: 2592000
|
|
127
|
+
}],
|
|
128
|
+
customErrorResponses: [{
|
|
129
|
+
errorCode: 404,
|
|
130
|
+
responseCode: 404,
|
|
131
|
+
responsePagePath: "/_NOT_FOUND_PAGE_/index.html"
|
|
132
|
+
}],
|
|
133
|
+
priceClass: "PriceClass_100",
|
|
134
|
+
restrictions: {
|
|
135
|
+
geoRestriction: {
|
|
136
|
+
restrictionType: "none"
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
viewerCertificate: {
|
|
140
|
+
cloudfrontDefaultCertificate: true
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
const domain = (_config$domain = config.domain) === null || _config$domain === void 0 ? void 0 : _config$domain.call(config, app.ctx);
|
|
145
|
+
|
|
146
|
+
if (domain) {
|
|
147
|
+
(0, _customDomain.applyCustomDomain)(deliveryCloudfront, domain);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
app.addOutputs({
|
|
151
|
+
// Cloudfront and S3 bucket used to host the single-page application (SPA). The URL of the distribution is mainly
|
|
152
|
+
// utilized by the Page Builder app's prerendering engine. Using this URL, it accesses the SPA and creates HTML snapshots.
|
|
153
|
+
// The files that are generated in that process are stored in the `deliveryStorage` S3 bucket further below.
|
|
154
|
+
appId: appCloudfront.output.id,
|
|
155
|
+
appStorage: appBucket.bucket.output.id,
|
|
156
|
+
appUrl: appCloudfront.output.domainName.apply(value => `https://${value}`),
|
|
157
|
+
// These are the Cloudfront and S3 bucket that will deliver static pages to the actual website visitors.
|
|
158
|
+
// The static HTML snapshots delivered from them still rely on the app's S3 bucket
|
|
159
|
+
// defined above, for serving static assets (JS, CSS, images).
|
|
160
|
+
deliveryId: deliveryCloudfront.output.id,
|
|
161
|
+
deliveryStorage: deliveryBucket.bucket.output.id,
|
|
162
|
+
deliveryUrl: deliveryCloudfront.output.domainName.apply(value => `https://${value}`)
|
|
163
|
+
});
|
|
164
|
+
return {
|
|
165
|
+
app: _objectSpread(_objectSpread({}, appBucket), {}, {
|
|
166
|
+
cloudfront: appCloudfront
|
|
167
|
+
}),
|
|
168
|
+
delivery: _objectSpread(_objectSpread({}, deliveryBucket), {}, {
|
|
169
|
+
cloudfront: deliveryCloudfront
|
|
170
|
+
})
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
});
|
|
175
|
+
exports.WebsiteApp = WebsiteApp;
|
|
176
|
+
|
|
177
|
+
function createWebsiteApp(config) {
|
|
178
|
+
return (0, _pulumiSdk.createGenericApplication)({
|
|
179
|
+
id: "website",
|
|
180
|
+
name: "website",
|
|
181
|
+
description: "Your project's public website.",
|
|
182
|
+
cli: {
|
|
183
|
+
// Default args for the "yarn webiny watch ..." command (we don't need deploy option while developing).
|
|
184
|
+
watch: {
|
|
185
|
+
deploy: false
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
async app(ctx) {
|
|
190
|
+
var _config$config;
|
|
191
|
+
|
|
192
|
+
// Create the app instance.
|
|
193
|
+
const app = new WebsiteApp(ctx); // Run the default application setup.
|
|
194
|
+
|
|
195
|
+
await app.setup(config || {}); // Run the custom user config.
|
|
196
|
+
|
|
197
|
+
await (config === null || config === void 0 ? void 0 : (_config$config = config.config) === null || _config$config === void 0 ? void 0 : _config$config.call(config, app, ctx));
|
|
198
|
+
return app;
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
onBeforeBuild: config === null || config === void 0 ? void 0 : config.onBeforeBuild,
|
|
202
|
+
onAfterBuild: config === null || config === void 0 ? void 0 : config.onAfterBuild,
|
|
203
|
+
onBeforeDeploy: config === null || config === void 0 ? void 0 : config.onBeforeDeploy,
|
|
204
|
+
onAfterDeploy: (0, _pulumiSdk.mergeAppHooks)(_WebsiteHookUpload.websiteUpload, _WebsiteHookRender.websiteRender, _WebsiteHookUpdatePbSettings.websiteUpdatePbSettings, config === null || config === void 0 ? void 0 : config.onAfterDeploy)
|
|
205
|
+
});
|
|
206
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["WebsiteApp.ts"],"names":["WebsiteApp","name","config","app","appBucket","appCloudfront","addResource","aws","cloudfront","Distribution","enabled","waitForDeployment","origins","origin","defaultRootObject","defaultCacheBehavior","compress","targetOriginId","originId","viewerProtocolPolicy","allowedMethods","cachedMethods","forwardedValues","cookies","forward","queryString","minTtl","defaultTtl","maxTtl","priceClass","customErrorResponses","errorCode","responseCode","responsePagePath","restrictions","geoRestriction","restrictionType","viewerCertificate","cloudfrontDefaultCertificate","deliveryBucket","deliveryCloudfront","originRequestPolicyId","orderedCacheBehaviors","headers","pathPattern","domain","ctx","addOutputs","appId","output","id","appStorage","bucket","appUrl","domainName","apply","value","deliveryId","deliveryStorage","deliveryUrl","delivery","createWebsiteApp","description","cli","watch","deploy","setup","onBeforeBuild","onAfterBuild","onBeforeDeploy","onAfterDeploy","websiteUpload","websiteRender","websiteUpdatePbSettings"],"mappings":";;;;;;;;;;;;AAAA;;AAEA;;AAOA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAQO,MAAMA,UAAU,GAAG,0BAAU;AAChCC,EAAAA,IAAI,EAAE,SAD0B;;AAEhCC,EAAAA,MAAM,CAACC,GAAD,EAAMD,MAAN,EAAgC;AAAA;;AAClC,UAAME,SAAS,GAAG,4CAAsBD,GAAtB,EAA2B,KAA3B,CAAlB;AAEA,UAAME,aAAa,GAAGF,GAAG,CAACG,WAAJ,CAAgBC,GAAG,CAACC,UAAJ,CAAeC,YAA/B,EAA6C;AAC/DR,MAAAA,IAAI,EAAE,KADyD;AAE/DC,MAAAA,MAAM,EAAE;AACJQ,QAAAA,OAAO,EAAE,IADL;AAEJC,QAAAA,iBAAiB,EAAE,IAFf;AAGJC,QAAAA,OAAO,EAAE,CAACR,SAAS,CAACS,MAAX,CAHL;AAIJC,QAAAA,iBAAiB,EAAE,YAJf;AAKJC,QAAAA,oBAAoB,EAAE;AAClBC,UAAAA,QAAQ,EAAE,IADQ;AAElBC,UAAAA,cAAc,EAAEb,SAAS,CAACS,MAAV,CAAiBK,QAFf;AAGlBC,UAAAA,oBAAoB,EAAE,mBAHJ;AAIlBC,UAAAA,cAAc,EAAE,CAAC,KAAD,EAAQ,MAAR,EAAgB,SAAhB,CAJE;AAKlBC,UAAAA,aAAa,EAAE,CAAC,KAAD,EAAQ,MAAR,EAAgB,SAAhB,CALG;AAMlBC,UAAAA,eAAe,EAAE;AACbC,YAAAA,OAAO,EAAE;AAAEC,cAAAA,OAAO,EAAE;AAAX,aADI;AAEbC,YAAAA,WAAW,EA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AA,GAAG,EAAE;AACD;AACAC,MAAAA,KAAK,EAAE;AACHC,QAAAA,MAAM,EAAE;AADL;AAFN,KAJuB;;AAU5B,UAAM9D,GAAN,CAAU2C,GAAV,EAAe;AAAA;;AACX;AACA,YAAM3C,GAAG,GAAG,IAAIH,UAAJ,CAAe8C,GAAf,CAAZ,CAFW,CAGX;;AACA,YAAM3C,GAAG,CAAC+D,KAAJ,CAAUhE,MAAM,IAAI,EAApB,CAAN,CAJW,CAKX;;AACA,aAAMA,MAAN,aAAMA,MAAN,yCAAMA,MAAM,CAAEA,MAAd,mDAAM,oBAAAA,MAAM,EAAWC,GAAX,EAAgB2C,GAAhB,CAAZ;AACA,aAAO3C,GAAP;AACH,KAlB2B;;AAmB5BgE,IAAAA,aAAa,EAAEjE,MAAF,aAAEA,MAAF,uBAAEA,MAAM,CAAEiE,aAnBK;AAoB5BC,IAAAA,YAAY,EAAElE,MAAF,aAAEA,MAAF,uBAAEA,MAAM,CAAEkE,YApBM;AAqB5BC,IAAAA,cAAc,EAAEnE,MAAF,aAAEA,MAAF,uBAAEA,MAAM,CAAEmE,cArBI;AAsB5BC,IAAAA,aAAa,EAAE,8BACXC,gCADW,EAEXC,gCAFW,EAGXC,oDAHW,EAIXvE,MAJW,aAIXA,MAJW,uBAIXA,MAAM,CAAEoE,aAJG;AAtBa,GAAzB,CAAP;AA6BH","sourcesContent":["import * as aws from \"@pulumi/aws\";\n\nimport {\n defineApp,\n ApplicationContext,\n createGenericApplication,\n mergeAppHooks\n} from \"@webiny/pulumi-sdk\";\n\nimport { createPublicAppBucket } from \"../createAppBucket\";\nimport { websiteUpload } from \"./WebsiteHookUpload\";\nimport { websiteRender } from \"./WebsiteHookRender\";\nimport { websiteUpdatePbSettings } from \"./WebsiteHookUpdatePbSettings\";\nimport { applyCustomDomain, CustomDomainParams } from \"../customDomain\";\nimport { ApplicationConfig } from \"@webiny/pulumi-sdk\";\n\nexport interface WebsiteAppConfig {\n /** Custom domain configuration */\n domain?(ctx: ApplicationContext): CustomDomainParams;\n}\n\nexport const WebsiteApp = defineApp({\n name: \"Website\",\n config(app, config: WebsiteAppConfig) {\n const appBucket = createPublicAppBucket(app, \"app\");\n\n const appCloudfront = app.addResource(aws.cloudfront.Distribution, {\n name: \"app\",\n config: {\n enabled: true,\n waitForDeployment: true,\n origins: [appBucket.origin],\n defaultRootObject: \"index.html\",\n defaultCacheBehavior: {\n compress: true,\n targetOriginId: appBucket.origin.originId,\n viewerProtocolPolicy: \"redirect-to-https\",\n allowedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n cachedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n forwardedValues: {\n cookies: { forward: \"none\" },\n queryString: false\n },\n // MinTTL <= DefaultTTL <= MaxTTL\n minTtl: 0,\n defaultTtl: 0,\n maxTtl: 0\n },\n priceClass: \"PriceClass_100\",\n customErrorResponses: [\n { errorCode: 404, responseCode: 404, responsePagePath: \"/index.html\" }\n ],\n restrictions: {\n geoRestriction: {\n restrictionType: \"none\"\n }\n },\n viewerCertificate: {\n cloudfrontDefaultCertificate: true\n }\n }\n });\n\n const deliveryBucket = createPublicAppBucket(app, \"delivery\");\n\n const deliveryCloudfront = app.addResource(aws.cloudfront.Distribution, {\n name: \"delivery\",\n config: {\n enabled: true,\n waitForDeployment: true,\n origins: [deliveryBucket.origin, appBucket.origin],\n defaultRootObject: \"index.html\",\n defaultCacheBehavior: {\n compress: true,\n targetOriginId: deliveryBucket.origin.originId,\n viewerProtocolPolicy: \"redirect-to-https\",\n allowedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n cachedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n originRequestPolicyId: \"\",\n forwardedValues: {\n cookies: { forward: \"none\" },\n queryString: true\n },\n // MinTTL <= DefaultTTL <= MaxTTL\n minTtl: 0,\n defaultTtl: 30,\n maxTtl: 30\n },\n orderedCacheBehaviors: [\n {\n compress: true,\n allowedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n cachedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n forwardedValues: {\n cookies: {\n forward: \"none\"\n },\n headers: [],\n queryString: false\n },\n pathPattern: \"/static/*\",\n viewerProtocolPolicy: \"allow-all\",\n targetOriginId: appBucket.origin.originId,\n // MinTTL <= DefaultTTL <= MaxTTL\n minTtl: 0,\n defaultTtl: 2592000, // 30 days\n maxTtl: 2592000\n }\n ],\n customErrorResponses: [\n {\n errorCode: 404,\n responseCode: 404,\n responsePagePath: \"/_NOT_FOUND_PAGE_/index.html\"\n }\n ],\n priceClass: \"PriceClass_100\",\n restrictions: {\n geoRestriction: {\n restrictionType: \"none\"\n }\n },\n viewerCertificate: {\n cloudfrontDefaultCertificate: true\n }\n }\n });\n\n const domain = config.domain?.(app.ctx);\n if (domain) {\n applyCustomDomain(deliveryCloudfront, domain);\n }\n\n app.addOutputs({\n // Cloudfront and S3 bucket used to host the single-page application (SPA). The URL of the distribution is mainly\n // utilized by the Page Builder app's prerendering engine. Using this URL, it accesses the SPA and creates HTML snapshots.\n // The files that are generated in that process are stored in the `deliveryStorage` S3 bucket further below.\n appId: appCloudfront.output.id,\n appStorage: appBucket.bucket.output.id,\n appUrl: appCloudfront.output.domainName.apply(value => `https://${value}`),\n // These are the Cloudfront and S3 bucket that will deliver static pages to the actual website visitors.\n // The static HTML snapshots delivered from them still rely on the app's S3 bucket\n // defined above, for serving static assets (JS, CSS, images).\n deliveryId: deliveryCloudfront.output.id,\n deliveryStorage: deliveryBucket.bucket.output.id,\n deliveryUrl: deliveryCloudfront.output.domainName.apply(value => `https://${value}`)\n });\n\n return {\n app: {\n ...appBucket,\n cloudfront: appCloudfront\n },\n delivery: {\n ...deliveryBucket,\n cloudfront: deliveryCloudfront\n }\n };\n }\n});\n\nexport type WebsiteApp = InstanceType<typeof WebsiteApp>;\n\nexport function createWebsiteApp(config?: WebsiteAppConfig & ApplicationConfig<WebsiteApp>) {\n return createGenericApplication({\n id: \"website\",\n name: \"website\",\n description: \"Your project's public website.\",\n cli: {\n // Default args for the \"yarn webiny watch ...\" command (we don't need deploy option while developing).\n watch: {\n deploy: false\n }\n },\n async app(ctx) {\n // Create the app instance.\n const app = new WebsiteApp(ctx);\n // Run the default application setup.\n await app.setup(config || {});\n // Run the custom user config.\n await config?.config?.(app, ctx);\n return app;\n },\n onBeforeBuild: config?.onBeforeBuild,\n onAfterBuild: config?.onAfterBuild,\n onBeforeDeploy: config?.onBeforeDeploy,\n onAfterDeploy: mergeAppHooks(\n websiteUpload,\n websiteRender,\n websiteUpdatePbSettings,\n config?.onAfterDeploy\n )\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const websiteRender: import("@webiny/pulumi-sdk").ApplicationHook;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.websiteRender = void 0;
|
|
9
|
+
|
|
10
|
+
var _lambda = _interopRequireDefault(require("aws-sdk/clients/lambda"));
|
|
11
|
+
|
|
12
|
+
var _pulumiSdk = require("@webiny/pulumi-sdk");
|
|
13
|
+
|
|
14
|
+
var _utils = require("@webiny/cli-plugin-deploy-pulumi/utils");
|
|
15
|
+
|
|
16
|
+
const websiteRender = (0, _pulumiSdk.defineAppHook)(async (params, context) => {
|
|
17
|
+
if (params.inputs.build === false) {
|
|
18
|
+
context.info(`"--no-build" argument detected - skipping Website re-rendering.`);
|
|
19
|
+
return;
|
|
20
|
+
} // 2. Get exports from `site` stack, for `args.env` environment.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const apiOutput = (0, _utils.getStackOutput)({
|
|
24
|
+
folder: "api",
|
|
25
|
+
env: params.env
|
|
26
|
+
});
|
|
27
|
+
context.info("Issuing a complete website render job...");
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const lambdaClient = new _lambda.default({
|
|
31
|
+
region: apiOutput["region"]
|
|
32
|
+
});
|
|
33
|
+
const response = await lambdaClient.invoke({
|
|
34
|
+
FunctionName: apiOutput["psQueueAdd"],
|
|
35
|
+
Payload: JSON.stringify({
|
|
36
|
+
render: {
|
|
37
|
+
path: "*",
|
|
38
|
+
configuration: {
|
|
39
|
+
db: {
|
|
40
|
+
namespace: "T#root"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
}).promise();
|
|
46
|
+
const {
|
|
47
|
+
error
|
|
48
|
+
} = JSON.parse(response.Payload);
|
|
49
|
+
|
|
50
|
+
if (error) {
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
await lambdaClient.invoke({
|
|
55
|
+
FunctionName: apiOutput["psQueueProcess"],
|
|
56
|
+
InvocationType: "Event"
|
|
57
|
+
}).promise();
|
|
58
|
+
context.success("Website re-render job successfully issued.");
|
|
59
|
+
context.info("Please note that it can take a couple of minutes for the website to be fully updated.");
|
|
60
|
+
} catch (e) {
|
|
61
|
+
context.error(`An error occurred while trying to update default Page Builder app's settings!`);
|
|
62
|
+
console.log(e);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
exports.websiteRender = websiteRender;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["WebsiteHookRender.ts"],"names":["websiteRender","params","context","inputs","build","info","apiOutput","folder","env","lambdaClient","LambdaClient","region","response","invoke","FunctionName","Payload","JSON","stringify","render","path","configuration","db","namespace","promise","error","parse","InvocationType","success","e","console","log"],"mappings":";;;;;;;;;AAAA;;AAEA;;AACA;;AAEO,MAAMA,aAAa,GAAG,8BAAc,OAAOC,MAAP,EAAeC,OAAf,KAA2B;AAClE,MAAID,MAAM,CAACE,MAAP,CAAcC,KAAd,KAAwB,KAA5B,EAAmC;AAC/BF,IAAAA,OAAO,CAACG,IAAR,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":["import LambdaClient from \"aws-sdk/clients/lambda\";\n\nimport { defineAppHook } from \"@webiny/pulumi-sdk\";\nimport { getStackOutput } from \"@webiny/cli-plugin-deploy-pulumi/utils\";\n\nexport const websiteRender = defineAppHook(async (params, context) => {\n if (params.inputs.build === false) {\n context.info(`\"--no-build\" argument detected - skipping Website re-rendering.`);\n return;\n }\n\n // 2. Get exports from `site` stack, for `args.env` environment.\n const apiOutput = getStackOutput({ folder: \"api\", env: params.env });\n\n context.info(\"Issuing a complete website render job...\");\n\n try {\n const lambdaClient = new LambdaClient({ region: apiOutput[\"region\"] });\n\n const response = await lambdaClient\n .invoke({\n FunctionName: apiOutput[\"psQueueAdd\"],\n Payload: JSON.stringify({\n render: {\n path: \"*\",\n configuration: {\n db: {\n namespace: \"T#root\"\n }\n }\n }\n })\n })\n .promise();\n\n const { error } = JSON.parse(response.Payload as string);\n if (error) {\n throw error;\n }\n\n await lambdaClient\n .invoke({\n FunctionName: apiOutput[\"psQueueProcess\"],\n InvocationType: \"Event\"\n })\n .promise();\n\n context.success(\"Website re-render job successfully issued.\");\n context.info(\n \"Please note that it can take a couple of minutes for the website to be fully updated.\"\n );\n } catch (e) {\n context.error(\n `An error occurred while trying to update default Page Builder app's settings!`\n );\n console.log(e);\n }\n});\n"]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.websiteUpdatePbSettings = void 0;
|
|
9
|
+
|
|
10
|
+
var _lambda = _interopRequireDefault(require("aws-sdk/clients/lambda"));
|
|
11
|
+
|
|
12
|
+
var _pulumiSdk = require("@webiny/pulumi-sdk");
|
|
13
|
+
|
|
14
|
+
var _utils = require("@webiny/cli-plugin-deploy-pulumi/utils");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* On every deployment of the Website project application, this plugin ensures
|
|
18
|
+
* Webiny Page Builder application's settings are correctly updated.
|
|
19
|
+
*/
|
|
20
|
+
const websiteUpdatePbSettings = (0, _pulumiSdk.defineAppHook)(async (params, context) => {
|
|
21
|
+
// 1. Get exports from `site` stack, for `args.env` environment.
|
|
22
|
+
const websiteOutput = (0, _utils.getStackOutput)({
|
|
23
|
+
folder: "apps/website",
|
|
24
|
+
env: params.env
|
|
25
|
+
}); // 2. Get exports from `api` stack, again, for `args.env` environment.
|
|
26
|
+
|
|
27
|
+
const apiOutput = (0, _utils.getStackOutput)({
|
|
28
|
+
folder: "api",
|
|
29
|
+
env: params.env
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!apiOutput) {
|
|
33
|
+
context.warning(`API was not deployed yet. Could not update page builder settings.`);
|
|
34
|
+
return;
|
|
35
|
+
} // 3. Let's update relevant Page Builder app's URLs, by invoking the `updateSettings` function,
|
|
36
|
+
// which has been exported from the `api` stack for this exact purpose.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
context.success(`Updating Page Builder application's prerendering settings...`);
|
|
41
|
+
const lambdaClient = new _lambda.default({
|
|
42
|
+
region: apiOutput["region"]
|
|
43
|
+
});
|
|
44
|
+
const response = await lambdaClient.invoke({
|
|
45
|
+
FunctionName: apiOutput["updatePbSettingsFunction"],
|
|
46
|
+
Payload: JSON.stringify({
|
|
47
|
+
data: {
|
|
48
|
+
websiteUrl: websiteOutput["deliveryUrl"],
|
|
49
|
+
websitePreviewUrl: websiteOutput["appUrl"],
|
|
50
|
+
prerendering: {
|
|
51
|
+
app: {
|
|
52
|
+
url: websiteOutput["appUrl"]
|
|
53
|
+
},
|
|
54
|
+
storage: {
|
|
55
|
+
name: websiteOutput["deliveryStorage"]
|
|
56
|
+
},
|
|
57
|
+
meta: {
|
|
58
|
+
cloudfront: {
|
|
59
|
+
distributionId: websiteOutput["deliveryId"]
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
}).promise();
|
|
66
|
+
const {
|
|
67
|
+
error
|
|
68
|
+
} = JSON.parse(response.Payload);
|
|
69
|
+
|
|
70
|
+
if (error) {
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
context.success(`Page Builder application's prerendering settings updated.`);
|
|
75
|
+
} catch (e) {
|
|
76
|
+
context.error(`An error occurred while trying to update default Page Builder app's settings!`);
|
|
77
|
+
console.log(e);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
exports.websiteUpdatePbSettings = websiteUpdatePbSettings;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["WebsiteHookUpdatePbSettings.ts"],"names":["websiteUpdatePbSettings","params","context","websiteOutput","folder","env","apiOutput","warning","success","lambdaClient","LambdaClient","region","response","invoke","FunctionName","Payload","JSON","stringify","data","websiteUrl","websitePreviewUrl","prerendering","app","url","storage","name","meta","cloudfront","distributionId","promise","error","parse","e","console","log"],"mappings":";;;;;;;;;AAAA;;AAEA;;AACA;;AAEA;AACA;AACA;AACA;AACO,MAAMA,uBAAuB,GAAG,8BAAc,OAAOC,MAAP,EAAeC,OAAf,KAA2B;AAC5E;AACA,QAAMC,aAAa,GAAG,2BAAe;AAAEC,IAAAA,MAAM,EAAE,cAAV;AAA0BC,IAAAA,GAAG,EAAEJ,MAAM,CAACI;AAAtC,GAAf,CAAtB,CAF4E,CAI5E;;AACA,QAAMC,SAAS,GAAG,2BAAe;AAAEF,IAAAA,MAAM,EAAE,KAAV;AAAiBC,IAAAA,GAAG,EAAEJ,MAAM,CAACI;AAA7B,GAAf,CAAlB;;AACA,MAAI,CAACC,SAAL,EAAgB;AACZJ,IAAAA,OAAO,CAACK,OAAR,CAAiB,mEAAjB;AACA;AACH,GAT2E,CAW5E;AACA;;;AACA,MAAI;AACAL,IAAAA,OAAO,CAACM,OAAR,CAAiB,8DAAjB;AAEA,UAAMC,YAAY,GAAG,IAAIC,eAAJ,CAAiB;AAAEC,MAAAA,MAAM,EAAEL,SAAS,CAAC,QAAD;AAAnB,KAAjB,CAArB;AAEA,UAAMM,QAAQ,GAAG,MAAMH,YAAY,CAC9BI,MADkB,CACX;AACJC,MAAAA,YAAY,EAAER,SAAS,CAAC,0BAAD,CADnB;AAEJS,MAAAA,OAAO,EAAEC,IAAI,CAACC,SAAL,CAAe;AACpBC,QAAAA,IAAI,EAAE;AACFC,UAAAA,UAAU,EAAEhB,aAAa,CAAC,aAAD,CADvB;AAEFiB,UAAAA,iBAAiB,EAAEjB,aAAa,CAAC,QAAD,CAF9B;AAGFkB,UAAAA,YAAY,EAAE;AACVC,YAAAA,GAAG,EAAE;AACDC,cAAAA,GAAG,EAAEpB,aAAa,CAAC,QAAD;AADjB,aADK;AAIVqB,YAAAA,OAAO,EAAE;AACLC,cAAAA,IAAI,EAAEtB,aAAa,CAAC,iBAAD;AADd,aAJC;AAOVuB,YAAAA,IAAI,EAAE;AACFC,cAAAA,UAAU,EAAE;AACRC,gBAAAA,cAAc,EAAEzB,aAAa,CAAC,YAAD;AADrB;AADV;AAPI;AAHZ;AADc,OAAf;AAFL,KADW,EAuBlB0B,OAvBkB,EAAvB;AAyBA,UAAM;AAAEC,MAAAA;AAAF,QAAYd,IAAI,CAACe,KAAL,CAAWnB,QAAQ,CAACG,OAApB,CAAlB;;AACA,QAAIe,KAAJ,EAAW;AACP,YAAMA,KAAN;AACH;;AAED5B,IAAAA,OAAO,CAACM,OAAR,CAAiB,2DAAjB;AACH,GApCD,CAoCE,OAAOwB,CAAP,EAAU;AACR9B,IAAAA,OAAO,CAAC4B,KAAR,CACK,+EADL;AAGAG,IAAAA,OAAO,CAACC,GAAR,CAAYF,CAAZ;AACH;AACJ,CAvDsC,CAAhC","sourcesContent":["import LambdaClient from \"aws-sdk/clients/lambda\";\n\nimport { defineAppHook } from \"@webiny/pulumi-sdk\";\nimport { getStackOutput } from \"@webiny/cli-plugin-deploy-pulumi/utils\";\n\n/**\n * On every deployment of the Website project application, this plugin ensures\n * Webiny Page Builder application's settings are correctly updated.\n */\nexport const websiteUpdatePbSettings = defineAppHook(async (params, context) => {\n // 1. Get exports from `site` stack, for `args.env` environment.\n const websiteOutput = getStackOutput({ folder: \"apps/website\", env: params.env });\n\n // 2. Get exports from `api` stack, again, for `args.env` environment.\n const apiOutput = getStackOutput({ folder: \"api\", env: params.env });\n if (!apiOutput) {\n context.warning(`API was not deployed yet. Could not update page builder settings.`);\n return;\n }\n\n // 3. Let's update relevant Page Builder app's URLs, by invoking the `updateSettings` function,\n // which has been exported from the `api` stack for this exact purpose.\n try {\n context.success(`Updating Page Builder application's prerendering settings...`);\n\n const lambdaClient = new LambdaClient({ region: apiOutput[\"region\"] });\n\n const response = await lambdaClient\n .invoke({\n FunctionName: apiOutput[\"updatePbSettingsFunction\"],\n Payload: JSON.stringify({\n data: {\n websiteUrl: websiteOutput[\"deliveryUrl\"],\n websitePreviewUrl: websiteOutput[\"appUrl\"],\n prerendering: {\n app: {\n url: websiteOutput[\"appUrl\"]\n },\n storage: {\n name: websiteOutput[\"deliveryStorage\"]\n },\n meta: {\n cloudfront: {\n distributionId: websiteOutput[\"deliveryId\"]\n }\n }\n }\n }\n })\n })\n .promise();\n\n const { error } = JSON.parse(response.Payload as string);\n if (error) {\n throw error;\n }\n\n context.success(`Page Builder application's prerendering settings updated.`);\n } catch (e) {\n context.error(\n `An error occurred while trying to update default Page Builder app's settings!`\n );\n console.log(e);\n }\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const websiteUpload: import("@webiny/pulumi-sdk").ApplicationHook;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.websiteUpload = void 0;
|
|
9
|
+
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
|
|
12
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
13
|
+
|
|
14
|
+
var _pulumiSdk = require("@webiny/pulumi-sdk");
|
|
15
|
+
|
|
16
|
+
var _utils = require("@webiny/cli-plugin-deploy-pulumi/utils");
|
|
17
|
+
|
|
18
|
+
var _uploadFolderToS = _interopRequireDefault(require("@webiny/cli-plugin-deploy-pulumi/utils/aws/uploadFolderToS3"));
|
|
19
|
+
|
|
20
|
+
const websiteUpload = (0, _pulumiSdk.defineAppHook)(async (params, context) => {
|
|
21
|
+
if (params.inputs.build === false) {
|
|
22
|
+
context.info(`"--no-build" argument detected - skipping React application upload.`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
context.info("Uploading React application...");
|
|
27
|
+
const appRoot = params.projectApplication.root;
|
|
28
|
+
|
|
29
|
+
const buildFolderPath = _path.default.join(appRoot, "code", "build");
|
|
30
|
+
|
|
31
|
+
if (!_fs.default.existsSync(buildFolderPath)) {
|
|
32
|
+
throw new Error("Cannot continue, build folder not found.");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const start = new Date().getTime();
|
|
36
|
+
const websiteOutput = (0, _utils.getStackOutput)({
|
|
37
|
+
folder: "apps/website",
|
|
38
|
+
env: params.env
|
|
39
|
+
});
|
|
40
|
+
await (0, _uploadFolderToS.default)({
|
|
41
|
+
path: buildFolderPath,
|
|
42
|
+
bucket: websiteOutput["appStorage"],
|
|
43
|
+
acl: "public-read",
|
|
44
|
+
onFileUploadSuccess: ({
|
|
45
|
+
paths
|
|
46
|
+
}) => {
|
|
47
|
+
context.success(paths.relative);
|
|
48
|
+
},
|
|
49
|
+
onFileUploadError: ({
|
|
50
|
+
paths,
|
|
51
|
+
error
|
|
52
|
+
}) => {
|
|
53
|
+
context.error("Failed to upload " + context.error.hl(paths.relative));
|
|
54
|
+
console.log(error);
|
|
55
|
+
},
|
|
56
|
+
onFileUploadSkip: ({
|
|
57
|
+
paths
|
|
58
|
+
}) => {
|
|
59
|
+
context.info(`Skipping ${context.info.hl(paths.relative)}, already exists.`);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const duration = (new Date().getTime() - start) / 1000;
|
|
63
|
+
context.success(`React application successfully uploaded in ${context.success.hl(duration)}s.`);
|
|
64
|
+
});
|
|
65
|
+
exports.websiteUpload = websiteUpload;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["WebsiteHookUpload.ts"],"names":["websiteUpload","params","context","inputs","build","info","appRoot","projectApplication","root","buildFolderPath","path","join","fs","existsSync","Error","start","Date","getTime","websiteOutput","folder","env","bucket","acl","onFileUploadSuccess","paths","success","relative","onFileUploadError","error","hl","console","log","onFileUploadSkip","duration"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;AAEO,MAAMA,aAAa,GAAG,8BAAc,OAAOC,MAAP,EAAeC,OAAf,KAA2B;AAClE,MAAID,MAAM,CAACE,MAAP,CAAcC,KAAd,KAAwB,KAA5B,EAAmC;AAC/BF,IAAAA,OAAO,CAACG,IAAR,CAAc,qEAAd;AACA;AACH;;AAEDH,EAAAA,OAAO,CAACG,IAAR,CAAa,gCAAb;AAEA,QAAMC,OAAO,GAAGL,MAAM,CAACM,kBAAP,CAA0BC,IAA1C;;AACA,QAAMC,eAAe,GAAGC,cAAKC,IAAL,CAAUL,OAAV,EAAmB,MAAnB,EAA2B,OAA3B,CAAxB;;AACA,MAAI,CAACM,YAAGC,UAAH,CAAcJ,eAAd,CAAL,EAAqC;AACjC,UAAM,IAAIK,KAAJ,CAAU,0CAAV,CAAN;AACH;;AAED,QAAMC,KAAK,GAAG,IAAIC,IAAJ,GAAWC,OAAX,EAAd;AACA,QAAMC,aAAa,GAAG,2BAAe;AACjCC,IAAAA,MAAM,EAAE,cADyB;AAEjCC,IAAAA,GAAG,EAAEnB,MAAM,CAACmB;AAFqB,GAAf,CAAtB;AAKA,QAAM,8BAAiB;AACnBV,IAAAA,IAAI,EAAED,eADa;AAEnBY,IAAAA,MAAM,EAAEH,aAAa,CAAC,YAAD,CAFF;AAGnBI,IAAAA,GAAG,EAAE,aAHc;AAInBC,IAAAA,mBAAmB,EAAE,CAAC;AAAEC,MAAAA;AAAF,KAAD,KAAe;AAChCtB,MAAAA,OAAO,CAACuB,OAAR,CAAgBD,KAAK,CAACE,QAAtB;AACH,KANkB;AAOnBC,IAAAA,iBAAiB,EAAE,CAAC;AAAEH,MAAAA,KAAF;AAASI,MAAAA;AAAT,KAAD,KAAsB;AACrC1B,MAAAA,OAAO,CAAC0B,KAAR,CAAc,sBAAsB1B,OAAO,CAAC0B,KAAR,CAAcC,EAAd,CAAiBL,KAAK,CAACE,QAAvB,CAApC;AACAI,MAAAA,OAAO,CAACC,GAAR,CAAYH,KAAZ;AACH,KAVkB;AAWnBI,IAAAA,gBAAgB,EAAE,CAAC;AAAER,MAAAA;AAAF,KAAD,KAAe;AAC7BtB,MAAAA,OAAO,CAACG,IAAR,CAAc,YAAWH,OAAO,CAACG,IAAR,CAAawB,EAAb,CAAgBL,KAAK,CAACE,QAAtB,CAAgC,mBAAzD;AACH;AAbkB,GAAjB,CAAN;AAgBA,QAAMO,QAAQ,GAAG,CAAC,IAAIjB,IAAJ,GAAWC,OAAX,KAAuBF,KAAxB,IAAiC,IAAlD;AAEAb,EAAAA,OAAO,CAACuB,OAAR,CAAiB,8CAA6CvB,OAAO,CAACuB,OAAR,CAAgBI,EAAhB,CAAmBI,QAAnB,CAA6B,IAA3F;AACH,CAvC4B,CAAtB","sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\n\nimport { defineAppHook } from \"@webiny/pulumi-sdk\";\nimport { getStackOutput } from \"@webiny/cli-plugin-deploy-pulumi/utils\";\nimport uploadFolderToS3 from \"@webiny/cli-plugin-deploy-pulumi/utils/aws/uploadFolderToS3\";\n\nexport const websiteUpload = defineAppHook(async (params, context) => {\n if (params.inputs.build === false) {\n context.info(`\"--no-build\" argument detected - skipping React application upload.`);\n return;\n }\n\n context.info(\"Uploading React application...\");\n\n const appRoot = params.projectApplication.root;\n const buildFolderPath = path.join(appRoot, \"code\", \"build\");\n if (!fs.existsSync(buildFolderPath)) {\n throw new Error(\"Cannot continue, build folder not found.\");\n }\n\n const start = new Date().getTime();\n const websiteOutput = getStackOutput({\n folder: \"apps/website\",\n env: params.env\n });\n\n await uploadFolderToS3({\n path: buildFolderPath,\n bucket: websiteOutput[\"appStorage\"],\n acl: \"public-read\",\n onFileUploadSuccess: ({ paths }) => {\n context.success(paths.relative);\n },\n onFileUploadError: ({ paths, error }) => {\n context.error(\"Failed to upload \" + context.error.hl(paths.relative));\n console.log(error);\n },\n onFileUploadSkip: ({ paths }) => {\n context.info(`Skipping ${context.info.hl(paths.relative)}, already exists.`);\n }\n });\n\n const duration = (new Date().getTime() - start) / 1000;\n\n context.success(`React application successfully uploaded in ${context.success.hl(duration)}s.`);\n});\n"]}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
DocumentClient
|
|
5
|
-
} = require("aws-sdk/clients/dynamodb");
|
|
5
|
+
} = require("aws-sdk/clients/dynamodb"); // Since Lambda@Edge doesn't support ENV variables, the easiest way to pass
|
|
6
|
+
// config values to it is to inject them into the source code before deploy.
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
const DB_TABLE_NAME = "{DB_TABLE_NAME}";
|
|
8
10
|
const DB_TABLE_REGION = "{DB_TABLE_REGION}";
|
|
@@ -11,11 +13,33 @@ const documentClient = new DocumentClient({
|
|
|
11
13
|
region: DB_TABLE_REGION
|
|
12
14
|
});
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
function sanitizeRequestURI(uri) {
|
|
17
|
+
// Make sure that `/` is not appended to index.html, or any path with extension.
|
|
18
|
+
// We remove all slashes, filter out empty values, and reconstruct the path following
|
|
19
|
+
// the fact that every page (slug) has a dedicated folder in the S3 bucket, and an `index.html`
|
|
20
|
+
// file with the actual page HTML.
|
|
21
|
+
const parts = uri.split("/").filter(Boolean); // This means that a `/` (homepage) was requested. When the homepage is prerendered, we place its files
|
|
22
|
+
// into the root of the tenant subfolder, e.g., `/root/index.html`.
|
|
23
|
+
|
|
24
|
+
if (!parts.length) {
|
|
25
|
+
return "/index.html";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const lastPart = parts[parts.length - 1]; // If there's a `.` in the last part of the path, we assume it's a file extension.
|
|
29
|
+
// In this case, we can reconstruct the path by joining parts with slashes.
|
|
16
30
|
|
|
31
|
+
if (lastPart.includes(".")) {
|
|
32
|
+
return ["", ...parts].join("/");
|
|
33
|
+
} // Otherwise, we assume it's a page slug, which needs to point to page's subfolder.
|
|
34
|
+
// We construct a valid S3 bucket path to an HTML file.
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
return ["", ...parts, "index.html"].join("/");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function handleOriginRequest(request) {
|
|
17
41
|
const requestedDomain = request.headers.host[0].value;
|
|
18
|
-
const originDomain = request.origin.custom.domainName; // Find tenant by domain
|
|
42
|
+
const originDomain = request.origin.custom.domainName; // Find tenant by domain. This record is stored to the DB using the Tenant Manager app.
|
|
19
43
|
|
|
20
44
|
const params = {
|
|
21
45
|
TableName: DB_TABLE_NAME,
|
|
@@ -29,14 +53,36 @@ exports.handler = async event => {
|
|
|
29
53
|
} = await documentClient.get(params).promise();
|
|
30
54
|
|
|
31
55
|
if (Item) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
56
|
+
const uri = sanitizeRequestURI(request.uri); // To be on the safe side, make sure the requested uri doesn't already include the tenant ID.
|
|
57
|
+
|
|
58
|
+
if (uri.startsWith(`/${Item.tenant}/`)) {
|
|
59
|
+
request.uri = uri;
|
|
60
|
+
} else {
|
|
61
|
+
// Prepend the tenant ID, to point to the correct S3 bucket folder.
|
|
62
|
+
request.uri = `/${Item.tenant}${uri}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
console.log(`Rewriting request from "${uri}" to "${request.uri}"`);
|
|
35
66
|
} else {
|
|
36
67
|
console.log(`Failed to find a tenant for domain "${requestedDomain}"`);
|
|
37
|
-
} //
|
|
68
|
+
} // At this point, the value of the `Host` header is set to the custom domain.
|
|
69
|
+
// Before forwarding the request to the S3 bucket, we need to set the `Host` header
|
|
70
|
+
// to the value of the origin (S3 bucket URL).
|
|
38
71
|
|
|
39
72
|
|
|
40
73
|
request.headers.host[0].value = originDomain;
|
|
74
|
+
return request;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
exports.handler = async event => {
|
|
78
|
+
const {
|
|
79
|
+
request,
|
|
80
|
+
config
|
|
81
|
+
} = event.Records[0].cf;
|
|
82
|
+
|
|
83
|
+
if (config.eventType === "origin-request") {
|
|
84
|
+
return handleOriginRequest(request);
|
|
85
|
+
}
|
|
86
|
+
|
|
41
87
|
return request;
|
|
42
88
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["request.js"],"names":["DocumentClient","require","DB_TABLE_NAME","DB_TABLE_REGION","documentClient","convertEmptyValues","region","
|
|
1
|
+
{"version":3,"sources":["request.js"],"names":["DocumentClient","require","DB_TABLE_NAME","DB_TABLE_REGION","documentClient","convertEmptyValues","region","sanitizeRequestURI","uri","parts","split","filter","Boolean","length","lastPart","includes","join","handleOriginRequest","request","requestedDomain","headers","host","value","originDomain","origin","custom","domainName","params","TableName","Key","PK","SK","Item","get","promise","startsWith","tenant","console","log","exports","handler","event","config","Records","cf","eventType"],"mappings":";;AAAA,MAAM;AAAEA,EAAAA;AAAF,IAAqBC,OAAO,CAAC,0BAAD,CAAlC,C,CAEA;AACA;;;AACA,MAAMC,aAAa,GAAG,iBAAtB;AACA,MAAMC,eAAe,GAAG,mBAAxB;AAEA,MAAMC,cAAc,GAAG,IAAIJ,cAAJ,CAAmB;AACtC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D,kBAAkB,CAACW,OAAO,CAACV,GAAT,CAA9B,CADM,CAGN;;AACA,QAAIA,GAAG,CAAC2B,UAAJ,CAAgB,IAAGH,IAAI,CAACI,MAAO,GAA/B,CAAJ,EAAwC;AACpClB,MAAAA,OAAO,CAACV,GAAR,GAAcA,GAAd;AACH,KAFD,MAEO;AACH;AACAU,MAAAA,OAAO,CAACV,GAAR,GAAe,IAAGwB,IAAI,CAACI,MAAO,GAAE5B,GAAI,EAApC;AACH;;AAED6B,IAAAA,OAAO,CAACC,GAAR,CAAa,2BAA0B9B,GAAI,SAAQU,OAAO,CAACV,GAAI,GAA/D;AACH,GAZD,MAYO;AACH6B,IAAAA,OAAO,CAACC,GAAR,CAAa,uCAAsCnB,eAAgB,GAAnE;AACH,GA5BuC,CA8BxC;AACA;AACA;;;AACAD,EAAAA,OAAO,CAACE,OAAR,CAAgBC,IAAhB,CAAqB,CAArB,EAAwBC,KAAxB,GAAgCC,YAAhC;AAEA,SAAOL,OAAP;AACH;;AAEDqB,OAAO,CAACC,OAAR,GAAkB,MAAMC,KAAN,IAAe;AAC7B,QAAM;AAAEvB,IAAAA,OAAF;AAAWwB,IAAAA;AAAX,MAAsBD,KAAK,CAACE,OAAN,CAAc,CAAd,EAAiBC,EAA7C;;AAEA,MAAIF,MAAM,CAACG,SAAP,KAAqB,gBAAzB,EAA2C;AACvC,WAAO5B,mBAAmB,CAACC,OAAD,CAA1B;AACH;;AAED,SAAOA,OAAP;AACH,CARD","sourcesContent":["const { DocumentClient } = require(\"aws-sdk/clients/dynamodb\");\n\n// Since Lambda@Edge doesn't support ENV variables, the easiest way to pass\n// config values to it is to inject them into the source code before deploy.\nconst DB_TABLE_NAME = \"{DB_TABLE_NAME}\";\nconst DB_TABLE_REGION = \"{DB_TABLE_REGION}\";\n\nconst documentClient = new DocumentClient({\n convertEmptyValues: true,\n region: DB_TABLE_REGION\n});\n\nfunction sanitizeRequestURI(uri) {\n // Make sure that `/` is not appended to index.html, or any path with extension.\n // We remove all slashes, filter out empty values, and reconstruct the path following\n // the fact that every page (slug) has a dedicated folder in the S3 bucket, and an `index.html`\n // file with the actual page HTML.\n const parts = uri.split(\"/\").filter(Boolean);\n\n // This means that a `/` (homepage) was requested. When the homepage is prerendered, we place its files\n // into the root of the tenant subfolder, e.g., `/root/index.html`.\n if (!parts.length) {\n return \"/index.html\";\n }\n\n const lastPart = parts[parts.length - 1];\n\n // If there's a `.` in the last part of the path, we assume it's a file extension.\n // In this case, we can reconstruct the path by joining parts with slashes.\n if (lastPart.includes(\".\")) {\n return [\"\", ...parts].join(\"/\");\n }\n\n // Otherwise, we assume it's a page slug, which needs to point to page's subfolder.\n // We construct a valid S3 bucket path to an HTML file.\n return [\"\", ...parts, \"index.html\"].join(\"/\");\n}\n\nasync function handleOriginRequest(request) {\n const requestedDomain = request.headers.host[0].value;\n const originDomain = request.origin.custom.domainName;\n\n // Find tenant by domain. This record is stored to the DB using the Tenant Manager app.\n const params = {\n TableName: DB_TABLE_NAME,\n Key: {\n PK: `DOMAIN#${requestedDomain}`,\n SK: \"A\"\n }\n };\n const { Item } = await documentClient.get(params).promise();\n\n if (Item) {\n const uri = sanitizeRequestURI(request.uri);\n\n // To be on the safe side, make sure the requested uri doesn't already include the tenant ID.\n if (uri.startsWith(`/${Item.tenant}/`)) {\n request.uri = uri;\n } else {\n // Prepend the tenant ID, to point to the correct S3 bucket folder.\n request.uri = `/${Item.tenant}${uri}`;\n }\n\n console.log(`Rewriting request from \"${uri}\" to \"${request.uri}\"`);\n } else {\n console.log(`Failed to find a tenant for domain \"${requestedDomain}\"`);\n }\n\n // At this point, the value of the `Host` header is set to the custom domain.\n // Before forwarding the request to the S3 bucket, we need to set the `Host` header\n // to the value of the origin (S3 bucket URL).\n request.headers.host[0].value = originDomain;\n\n return request;\n}\n\nexports.handler = async event => {\n const { request, config } = event.Records[0].cf;\n\n if (config.eventType === \"origin-request\") {\n return handleOriginRequest(request);\n }\n\n return request;\n};\n"]}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
WebsiteTenantRouter: true
|
|
8
|
+
};
|
|
6
9
|
Object.defineProperty(exports, "WebsiteTenantRouter", {
|
|
7
10
|
enumerable: true,
|
|
8
11
|
get: function () {
|
|
@@ -10,4 +13,18 @@ Object.defineProperty(exports, "WebsiteTenantRouter", {
|
|
|
10
13
|
}
|
|
11
14
|
});
|
|
12
15
|
|
|
13
|
-
var _WebsiteTenantRouter = require("./components/tenantRouter/WebsiteTenantRouter");
|
|
16
|
+
var _WebsiteTenantRouter = require("./components/tenantRouter/WebsiteTenantRouter");
|
|
17
|
+
|
|
18
|
+
var _apps = require("./apps");
|
|
19
|
+
|
|
20
|
+
Object.keys(_apps).forEach(function (key) {
|
|
21
|
+
if (key === "default" || key === "__esModule") return;
|
|
22
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
23
|
+
if (key in exports && exports[key] === _apps[key]) return;
|
|
24
|
+
Object.defineProperty(exports, key, {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _apps[key];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|