@wolsok/spa-cdk-stack 1.2.32 → 1.3.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/README.md +22 -0
- package/package.json +1 -1
- package/src/lib/spa/deployment-sources.d.ts +15 -0
- package/src/lib/spa/deployment-sources.js +79 -0
- package/src/lib/spa/deployment-sources.js.map +1 -0
- package/src/lib/spa/spa.construct.d.ts +17 -0
- package/src/lib/spa/spa.construct.js +29 -4
- package/src/lib/spa/spa.construct.js.map +1 -1
- package/src/lib/spa/trailing-slash-redirect.d.ts +7 -0
- package/src/lib/spa/trailing-slash-redirect.js +36 -0
- package/src/lib/spa/trailing-slash-redirect.js.map +1 -0
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ Features are:
|
|
|
15
15
|
regions.
|
|
16
16
|
- Redirect from HTTP to HTTPS with an ACM certificate.
|
|
17
17
|
- Route53 alias record creation,
|
|
18
|
+
- Optionally, a permanent redirect from `/path/` to `/path`.
|
|
18
19
|
|
|
19
20
|
## Usage
|
|
20
21
|
|
|
@@ -55,6 +56,27 @@ new SpaStack(app, 'MyApp', {
|
|
|
55
56
|
});
|
|
56
57
|
```
|
|
57
58
|
|
|
59
|
+
Each `addExtraAssets` call is one deployment, which unpacks all its sources into
|
|
60
|
+
one folder. So a file and a path below it, such as a page uploaded under its bare
|
|
61
|
+
path `blog` and another under `blog/first-post`, cannot share a call: the
|
|
62
|
+
construct throws at synth. Add the deeper paths in a call of their own:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
stack.spa.addExtraAssets(
|
|
66
|
+
[Source.data('blog', blogHtml)],
|
|
67
|
+
CacheControl.noCache()
|
|
68
|
+
);
|
|
69
|
+
stack.spa.addExtraAssets(
|
|
70
|
+
[Source.data('blog/first-post', postHtml)],
|
|
71
|
+
CacheControl.noCache()
|
|
72
|
+
);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
A site that uploads its prerendered pages under their bare paths (`/about`
|
|
76
|
+
holding `about/index.html`) can set `redirectTrailingSlash: true`, which
|
|
77
|
+
redirects `/about/` to `/about` (see its doc comment); without bare-path objects
|
|
78
|
+
the target falls back to `index.html` like any other miss.
|
|
79
|
+
|
|
58
80
|
## Building
|
|
59
81
|
|
|
60
82
|
## Running unit tests
|
package/package.json
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BucketDeployment } from 'aws-cdk-lib/aws-s3-deployment';
|
|
2
|
+
/**
|
|
3
|
+
* Throws when one source of the deployment holds a file at a path where
|
|
4
|
+
* another holds a folder, such as `Source.data('blog', …)` beside
|
|
5
|
+
* `Source.data('blog/first-post', …)`. The deployment's Lambda unpacks all
|
|
6
|
+
* its sources into one folder, so such a pair would fail only at deploy time
|
|
7
|
+
* with `Not a directory` and roll the stack back.
|
|
8
|
+
*
|
|
9
|
+
* It reads the staged folders of the local assets the sources bound as
|
|
10
|
+
* children of the deployment (`Source.asset`, `Source.data`,
|
|
11
|
+
* `Source.jsonData`), after their excludes. Zip files, sources from a bucket
|
|
12
|
+
* and staged paths that do not exist are not checked. A deployment with one
|
|
13
|
+
* source is not read at all.
|
|
14
|
+
*/
|
|
15
|
+
export declare function assertNoFileIsAnotherSourcesFolder(deployment: BucketDeployment): void;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertNoFileIsAnotherSourcesFolder = assertNoFileIsAnotherSourcesFolder;
|
|
4
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
5
|
+
const aws_s3_assets_1 = require("aws-cdk-lib/aws-s3-assets");
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
/**
|
|
9
|
+
* Throws when one source of the deployment holds a file at a path where
|
|
10
|
+
* another holds a folder, such as `Source.data('blog', …)` beside
|
|
11
|
+
* `Source.data('blog/first-post', …)`. The deployment's Lambda unpacks all
|
|
12
|
+
* its sources into one folder, so such a pair would fail only at deploy time
|
|
13
|
+
* with `Not a directory` and roll the stack back.
|
|
14
|
+
*
|
|
15
|
+
* It reads the staged folders of the local assets the sources bound as
|
|
16
|
+
* children of the deployment (`Source.asset`, `Source.data`,
|
|
17
|
+
* `Source.jsonData`), after their excludes. Zip files, sources from a bucket
|
|
18
|
+
* and staged paths that do not exist are not checked. A deployment with one
|
|
19
|
+
* source is not read at all.
|
|
20
|
+
*/
|
|
21
|
+
function assertNoFileIsAnotherSourcesFolder(deployment) {
|
|
22
|
+
const stagedFolders = deployment.node.children
|
|
23
|
+
.filter((child) => child instanceof aws_s3_assets_1.Asset)
|
|
24
|
+
.map((asset) => stagedFolderOf(asset))
|
|
25
|
+
.filter((folder) => folder !== undefined);
|
|
26
|
+
if (stagedFolders.length < 2) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// Within one folder no path is both, so every clash is between sources.
|
|
30
|
+
const trees = stagedFolders.map((folder) => readTree(folder));
|
|
31
|
+
const folders = new Set(trees.flatMap((tree) => [...tree.folders]));
|
|
32
|
+
const clash = trees
|
|
33
|
+
.flatMap((tree) => [...tree.files])
|
|
34
|
+
.find((file) => folders.has(file));
|
|
35
|
+
if (clash !== undefined) {
|
|
36
|
+
throw new Error(`"${clash}" is a file in one source and a folder in another of the ` +
|
|
37
|
+
'same deployment. A BucketDeployment unpacks all its sources into ' +
|
|
38
|
+
'one folder, so add them in separate addExtraAssets calls.');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function stagedFolderOf(asset) {
|
|
42
|
+
const staging = asset.node.children.find((child) => child instanceof aws_cdk_lib_1.AssetStaging);
|
|
43
|
+
if (staging === undefined) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const folder = staging.absoluteStagedPath;
|
|
47
|
+
return (0, node_fs_1.existsSync)(folder) && (0, node_fs_1.statSync)(folder).isDirectory()
|
|
48
|
+
? folder
|
|
49
|
+
: undefined;
|
|
50
|
+
}
|
|
51
|
+
function readTree(root) {
|
|
52
|
+
const tree = { files: new Set(), folders: new Set() };
|
|
53
|
+
const visit = (prefix) => {
|
|
54
|
+
for (const entry of (0, node_fs_1.readdirSync)((0, node_path_1.join)(root, prefix), {
|
|
55
|
+
withFileTypes: true,
|
|
56
|
+
})) {
|
|
57
|
+
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
58
|
+
if (entry.isDirectory()) {
|
|
59
|
+
tree.folders.add(path);
|
|
60
|
+
visit(path);
|
|
61
|
+
}
|
|
62
|
+
else if (isLinkToFolder((0, node_path_1.join)(root, path), entry)) {
|
|
63
|
+
// Not followed, so a link loop cannot recurse forever.
|
|
64
|
+
tree.folders.add(path);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
tree.files.add(path);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
visit('');
|
|
72
|
+
return tree;
|
|
73
|
+
}
|
|
74
|
+
/** A link to a folder, which the deployment unpacks as a folder. */
|
|
75
|
+
function isLinkToFolder(path, entry) {
|
|
76
|
+
return (entry.isSymbolicLink() &&
|
|
77
|
+
(0, node_fs_1.statSync)(path, { throwIfNoEntry: false })?.isDirectory() === true);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=deployment-sources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deployment-sources.js","sourceRoot":"","sources":["../../../../../../../libs/public/spa-cdk-stack/src/lib/spa/deployment-sources.ts"],"names":[],"mappings":";;AAyBA,gFAuBC;AAhDD,6CAA2C;AAC3C,6DAAkD;AAElD,qCAAoE;AACpE,yCAAiC;AAQjC;;;;;;;;;;;;GAYG;AACH,SAAgB,kCAAkC,CAChD,UAA4B;IAE5B,MAAM,aAAa,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ;SAC3C,MAAM,CAAC,CAAC,KAAK,EAAkB,EAAE,CAAC,KAAK,YAAY,qB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BAAQ,EAAC,IAAI,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,EAAE,WAAW,EAAE,KAAK,IAAI,CAClE,CAAC;AACJ,CAAC"}
|
|
@@ -29,6 +29,15 @@ export interface SpaProps {
|
|
|
29
29
|
* the later header wins. Wildcards may only appear in the last segment.
|
|
30
30
|
*/
|
|
31
31
|
cacheOverrides?: CacheOverride[];
|
|
32
|
+
/**
|
|
33
|
+
* Answer a path ending in `/` (other than `/`) with a permanent redirect to
|
|
34
|
+
* the path without it, query string kept, so `/about/` goes to `/about`
|
|
35
|
+
* instead of falling back to index.html. Only for sites that upload their
|
|
36
|
+
* pages under bare paths as well: without an `about` object the target
|
|
37
|
+
* falls back too. Takes the default behaviour's viewer-request slot.
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
redirectTrailingSlash?: boolean;
|
|
32
41
|
}
|
|
33
42
|
export interface CacheOverride {
|
|
34
43
|
/** Globs relative to buildOutputPath, e.g. `assets/manifest*.json`. */
|
|
@@ -61,6 +70,13 @@ export declare class SpaConstruct extends Construct {
|
|
|
61
70
|
* build output and before index.html. Use it for files that are not in
|
|
62
71
|
* buildOutputPath; for those that are, use noCacheFiles or cacheOverrides,
|
|
63
72
|
* or they are uploaded twice.
|
|
73
|
+
*
|
|
74
|
+
* All assets of one call go into one deployment, which unpacks them into
|
|
75
|
+
* one folder: a file and a path below it, such as `Source.data('blog', …)`
|
|
76
|
+
* and `Source.data('blog/first-post', …)`, cannot share a call. Such a call
|
|
77
|
+
* throws at synth, after the rejected deployment joined the construct, so
|
|
78
|
+
* the construct is no longer usable; add the deeper paths in a call of
|
|
79
|
+
* their own.
|
|
64
80
|
*/
|
|
65
81
|
addExtraAssets(assets: ISource[], cacheControl?: CacheControl, contentType?: string): void;
|
|
66
82
|
/** Adds a deployment that runs after the uploads so far and before index.html. */
|
|
@@ -68,6 +84,7 @@ export declare class SpaConstruct extends Construct {
|
|
|
68
84
|
private createBucket;
|
|
69
85
|
private createCertificate;
|
|
70
86
|
private createDistribution;
|
|
87
|
+
private createTrailingSlashRedirect;
|
|
71
88
|
private createARecord;
|
|
72
89
|
private createBucketDeployment;
|
|
73
90
|
private extractDomains;
|
|
@@ -11,6 +11,8 @@ const aws_route53_targets_1 = require("aws-cdk-lib/aws-route53-targets");
|
|
|
11
11
|
const aws_s3_1 = require("aws-cdk-lib/aws-s3");
|
|
12
12
|
const aws_s3_deployment_1 = require("aws-cdk-lib/aws-s3-deployment");
|
|
13
13
|
const constructs_1 = require("constructs");
|
|
14
|
+
const deployment_sources_1 = require("./deployment-sources");
|
|
15
|
+
const trailing_slash_redirect_1 = require("./trailing-slash-redirect");
|
|
14
16
|
/**
|
|
15
17
|
* Exclude globs that keep only `files`. '**' also skips every folder as a
|
|
16
18
|
* whole, so the folders above a nested file are re-included first, and
|
|
@@ -53,7 +55,7 @@ class SpaConstruct extends constructs_1.Construct {
|
|
|
53
55
|
this.spaName = spaName;
|
|
54
56
|
this.bucketDeployments = [];
|
|
55
57
|
const removalPolicy = props.bucketRemovalPolicy ?? defaultBucketRemovalPolicy;
|
|
56
|
-
const { buildOutputPath,
|
|
58
|
+
const { buildOutputPath, noCacheFiles = [], cacheOverrides = [] } = props;
|
|
57
59
|
const overrides = [
|
|
58
60
|
...(noCacheFiles.length > 0
|
|
59
61
|
? [{ files: noCacheFiles, cacheControl: aws_s3_deployment_1.CacheControl.noCache() }]
|
|
@@ -69,7 +71,7 @@ class SpaConstruct extends constructs_1.Construct {
|
|
|
69
71
|
const certificate = props.certificate ??
|
|
70
72
|
this.createCertificate(zone, ...certificateDomainNames(siteDomain));
|
|
71
73
|
this.bucket = this.createBucket(siteDomain, removalPolicy);
|
|
72
|
-
this.distribution = this.createDistribution(siteDomain, certificate, this.bucket,
|
|
74
|
+
this.distribution = this.createDistribution(siteDomain, certificate, this.bucket, props);
|
|
73
75
|
this.createARecord(siteDomain, this.distribution, zone);
|
|
74
76
|
// No deployment prunes: a pruning sync of index.html alone would delete
|
|
75
77
|
// every other file, and an upload whose asset did not change is not run
|
|
@@ -98,6 +100,13 @@ class SpaConstruct extends constructs_1.Construct {
|
|
|
98
100
|
* build output and before index.html. Use it for files that are not in
|
|
99
101
|
* buildOutputPath; for those that are, use noCacheFiles or cacheOverrides,
|
|
100
102
|
* or they are uploaded twice.
|
|
103
|
+
*
|
|
104
|
+
* All assets of one call go into one deployment, which unpacks them into
|
|
105
|
+
* one folder: a file and a path below it, such as `Source.data('blog', …)`
|
|
106
|
+
* and `Source.data('blog/first-post', …)`, cannot share a call. Such a call
|
|
107
|
+
* throws at synth, after the rejected deployment joined the construct, so
|
|
108
|
+
* the construct is no longer usable; add the deeper paths in a call of
|
|
109
|
+
* their own.
|
|
101
110
|
*/
|
|
102
111
|
addExtraAssets(assets, cacheControl, contentType) {
|
|
103
112
|
this.addUpload(assets, { cacheControl, contentType });
|
|
@@ -105,6 +114,7 @@ class SpaConstruct extends constructs_1.Construct {
|
|
|
105
114
|
/** Adds a deployment that runs after the uploads so far and before index.html. */
|
|
106
115
|
addUpload(sources, options) {
|
|
107
116
|
const deployment = this.createBucketDeployment(sources, options);
|
|
117
|
+
(0, deployment_sources_1.assertNoFileIsAnotherSourcesFolder)(deployment);
|
|
108
118
|
deployment.node.addDependency(this.lastUpload);
|
|
109
119
|
this.lastUpload = deployment;
|
|
110
120
|
this.bucketDeployments.push(deployment);
|
|
@@ -148,12 +158,12 @@ class SpaConstruct extends constructs_1.Construct {
|
|
|
148
158
|
});
|
|
149
159
|
return certificate;
|
|
150
160
|
}
|
|
151
|
-
createDistribution(siteDomain, certificate, siteBucket,
|
|
161
|
+
createDistribution(siteDomain, certificate, siteBucket, { extraAllowedOrigins = [], redirectTrailingSlash = false, }) {
|
|
152
162
|
const responseHeadersPolicy = new aws_cloudfront_1.ResponseHeadersPolicy(this, 'ResponseHeadersPolicy', {
|
|
153
163
|
corsBehavior: {
|
|
154
164
|
accessControlAllowCredentials: false,
|
|
155
165
|
accessControlAllowOrigins: [
|
|
156
|
-
...
|
|
166
|
+
...extraAllowedOrigins,
|
|
157
167
|
'https://' + siteDomain,
|
|
158
168
|
'http://localhost',
|
|
159
169
|
'http://127.0.0.1',
|
|
@@ -184,6 +194,14 @@ class SpaConstruct extends constructs_1.Construct {
|
|
|
184
194
|
compress: true,
|
|
185
195
|
allowedMethods: aws_cloudfront_1.AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
|
|
186
196
|
viewerProtocolPolicy: aws_cloudfront_1.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
197
|
+
functionAssociations: redirectTrailingSlash
|
|
198
|
+
? [
|
|
199
|
+
{
|
|
200
|
+
eventType: aws_cloudfront_1.FunctionEventType.VIEWER_REQUEST,
|
|
201
|
+
function: this.createTrailingSlashRedirect(),
|
|
202
|
+
},
|
|
203
|
+
]
|
|
204
|
+
: undefined,
|
|
187
205
|
},
|
|
188
206
|
});
|
|
189
207
|
new aws_cdk_lib_1.CfnOutput(this, `${this.spaName}-DistributionId`, {
|
|
@@ -191,6 +209,13 @@ class SpaConstruct extends constructs_1.Construct {
|
|
|
191
209
|
});
|
|
192
210
|
return distribution;
|
|
193
211
|
}
|
|
212
|
+
createTrailingSlashRedirect() {
|
|
213
|
+
return new aws_cloudfront_1.Function(this, 'TrailingSlashRedirect', {
|
|
214
|
+
code: aws_cloudfront_1.FunctionCode.fromInline(trailing_slash_redirect_1.TRAILING_SLASH_REDIRECT_SOURCE),
|
|
215
|
+
runtime: aws_cloudfront_1.FunctionRuntime.JS_2_0,
|
|
216
|
+
comment: 'Redirects /path/ to /path',
|
|
217
|
+
});
|
|
218
|
+
}
|
|
194
219
|
createARecord(siteDomain, distribution, zone) {
|
|
195
220
|
// Route53 alias record for the CloudFront distribution
|
|
196
221
|
new aws_route53_1.ARecord(this, 'SiteAliasRecord', {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spa.construct.js","sourceRoot":"","sources":["../../../../../../../libs/public/spa-cdk-stack/src/lib/spa/spa.construct.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"spa.construct.js","sourceRoot":"","sources":["../../../../../../../libs/public/spa-cdk-stack/src/lib/spa/spa.construct.ts"],"names":[],"mappings":";;;AAmHA,wDAGC;AAtHD,6CAAiE;AACjE,+EAI4C;AAC5C,+DAWoC;AACpC,+EAAoE;AACpE,yDAKiC;AACjC,yEAAmE;AACnE,+CAAwE;AACxE,qEAKuC;AACvC,2CAAuC;AACvC,6DAA0E;AAC1E,uEAA2E;AAqD3E;;;;GAIG;AACH,SAAS,WAAW,CAAC,KAAe;IAClC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7C,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;YACvD,qEAAqE;YACrE,oEAAoE;YACpE,MAAM,IAAI,KAAK,CACb,qDAAqD,IAAI,EAAE,CAC5D,CAAC;QACJ,CAAC;QACD,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC3E,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnB,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,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CAAC;QAC9B,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC7D,MAAM,iBAAiB,GACrB,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE,CAAC;QAE7D,oCAAoC;QACpC,IAAI,UAAU,KAAK,UAAU,EAAE,CAAC;YAC9B,OAAO,CAAC,IAAI,CACV,cAAc,UAAU,qEAAqE,UAAU,EAAE,CAC1G,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC;IACvD,CAAC;CACF;AAjSD,oCAiSC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CloudFront Function behind `SpaProps.redirectTrailingSlash`, for runtime
|
|
3
|
+
* `cloudfront-js-2.0` (plain ES5). The target keeps a single leading slash, so
|
|
4
|
+
* it never leaves the site. Kept as source text, so the spec runs exactly the
|
|
5
|
+
* code that is deployed.
|
|
6
|
+
*/
|
|
7
|
+
export declare const TRAILING_SLASH_REDIRECT_SOURCE = "\nfunction handler(event) {\n var request = event.request;\n var uri = request.uri;\n if (uri.length < 2 || uri.charAt(uri.length - 1) !== '/') {\n return request;\n }\n // One leading slash only: '//evil.com' would leave the site.\n var path = '/' + uri.replace(/^[\\/\\\\]+/, '').replace(/\\/+$/, '');\n var query = [];\n Object.keys(request.querystring).forEach(function (key) {\n var entry = request.querystring[key];\n var values = entry.multiValue || [entry];\n values.forEach(function (item) {\n query.push(key + '=' + item.value);\n });\n });\n return {\n statusCode: 301,\n statusDescription: 'Moved Permanently',\n headers: {\n location: { value: query.length ? path + '?' + query.join('&') : path },\n },\n };\n}\n";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TRAILING_SLASH_REDIRECT_SOURCE = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The CloudFront Function behind `SpaProps.redirectTrailingSlash`, for runtime
|
|
6
|
+
* `cloudfront-js-2.0` (plain ES5). The target keeps a single leading slash, so
|
|
7
|
+
* it never leaves the site. Kept as source text, so the spec runs exactly the
|
|
8
|
+
* code that is deployed.
|
|
9
|
+
*/
|
|
10
|
+
exports.TRAILING_SLASH_REDIRECT_SOURCE = `
|
|
11
|
+
function handler(event) {
|
|
12
|
+
var request = event.request;
|
|
13
|
+
var uri = request.uri;
|
|
14
|
+
if (uri.length < 2 || uri.charAt(uri.length - 1) !== '/') {
|
|
15
|
+
return request;
|
|
16
|
+
}
|
|
17
|
+
// One leading slash only: '//evil.com' would leave the site.
|
|
18
|
+
var path = '/' + uri.replace(/^[\\/\\\\]+/, '').replace(/\\/+$/, '');
|
|
19
|
+
var query = [];
|
|
20
|
+
Object.keys(request.querystring).forEach(function (key) {
|
|
21
|
+
var entry = request.querystring[key];
|
|
22
|
+
var values = entry.multiValue || [entry];
|
|
23
|
+
values.forEach(function (item) {
|
|
24
|
+
query.push(key + '=' + item.value);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
statusCode: 301,
|
|
29
|
+
statusDescription: 'Moved Permanently',
|
|
30
|
+
headers: {
|
|
31
|
+
location: { value: query.length ? path + '?' + query.join('&') : path },
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
//# sourceMappingURL=trailing-slash-redirect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trailing-slash-redirect.js","sourceRoot":"","sources":["../../../../../../../libs/public/spa-cdk-stack/src/lib/spa/trailing-slash-redirect.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACU,QAAA,8BAA8B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;CAyB7C,CAAC"}
|