quidproquo-deploy-awscdk 0.0.149 → 0.0.151
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -11,8 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.executeAPIGatewayEvent = void 0;
|
|
13
13
|
const executeAPIGatewayEvent = (event, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
console.log('event: ', JSON.stringify(event, null, 2));
|
|
15
|
+
console.log('process.env: ', JSON.stringify(process.env, null, 2));
|
|
16
16
|
const redirectConfig = JSON.parse(process.env.redirectConfig);
|
|
17
17
|
// For direct urls ~ Go straight to the url
|
|
18
18
|
let redirectUrl = redirectConfig.redirectUrl;
|
|
@@ -21,7 +21,7 @@ const executeAPIGatewayEvent = (event, context) => __awaiter(void 0, void 0, voi
|
|
|
21
21
|
const environment = JSON.parse(process.env.environment);
|
|
22
22
|
const featureEnvironment = JSON.parse(process.env.featureEnvironment || '""');
|
|
23
23
|
let baseDomain = redirectConfig.redirectUrl;
|
|
24
|
-
if (redirectConfig.addEnvironment) {
|
|
24
|
+
if (redirectConfig.addEnvironment && environment !== 'production') {
|
|
25
25
|
baseDomain = `${environment}.${baseDomain}`;
|
|
26
26
|
}
|
|
27
27
|
if (redirectConfig.addFeatureEnvironment && featureEnvironment) {
|
|
@@ -29,6 +29,15 @@ const executeAPIGatewayEvent = (event, context) => __awaiter(void 0, void 0, voi
|
|
|
29
29
|
}
|
|
30
30
|
redirectUrl = `https://${baseDomain}${event.path}`;
|
|
31
31
|
}
|
|
32
|
+
// Add query parameters if they exist
|
|
33
|
+
const queryParams = event.queryStringParameters;
|
|
34
|
+
if (queryParams) {
|
|
35
|
+
const queryString = Object.entries(queryParams)
|
|
36
|
+
.filter(([, value]) => value !== undefined) // Filter out undefined values
|
|
37
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
38
|
+
.join('&');
|
|
39
|
+
redirectUrl += `?${queryString}`;
|
|
40
|
+
}
|
|
32
41
|
return {
|
|
33
42
|
statusCode: 301,
|
|
34
43
|
body: '',
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@ import { APIGatewayEvent, Context } from 'aws-lambda';
|
|
|
2
2
|
import { SubdomainRedirectQPQWebServerConfigSetting } from 'quidproquo-webserver';
|
|
3
3
|
|
|
4
4
|
export const executeAPIGatewayEvent = async (event: APIGatewayEvent, context: Context) => {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
console.log('event: ', JSON.stringify(event, null, 2));
|
|
6
|
+
console.log('process.env: ', JSON.stringify(process.env, null, 2));
|
|
7
7
|
|
|
8
8
|
const redirectConfig: SubdomainRedirectQPQWebServerConfigSetting = JSON.parse(
|
|
9
9
|
process.env.redirectConfig as string,
|
|
@@ -14,18 +14,17 @@ export const executeAPIGatewayEvent = async (event: APIGatewayEvent, context: Co
|
|
|
14
14
|
|
|
15
15
|
// Otherwise it must be a domain redirect
|
|
16
16
|
if (!redirectConfig.redirectUrl.startsWith('http')) {
|
|
17
|
-
const environment:
|
|
18
|
-
process.env.environment as string,
|
|
19
|
-
);
|
|
17
|
+
const environment: string = JSON.parse(process.env.environment as string);
|
|
20
18
|
|
|
21
|
-
const featureEnvironment:
|
|
19
|
+
const featureEnvironment: string = JSON.parse(
|
|
22
20
|
(process.env.featureEnvironment as string | undefined) || '""',
|
|
23
21
|
);
|
|
24
22
|
|
|
25
23
|
let baseDomain = redirectConfig.redirectUrl;
|
|
26
|
-
if (redirectConfig.addEnvironment) {
|
|
24
|
+
if (redirectConfig.addEnvironment && environment !== 'production') {
|
|
27
25
|
baseDomain = `${environment}.${baseDomain}`;
|
|
28
26
|
}
|
|
27
|
+
|
|
29
28
|
if (redirectConfig.addFeatureEnvironment && featureEnvironment) {
|
|
30
29
|
baseDomain = `${featureEnvironment}.${baseDomain}`;
|
|
31
30
|
}
|
|
@@ -33,6 +32,16 @@ export const executeAPIGatewayEvent = async (event: APIGatewayEvent, context: Co
|
|
|
33
32
|
redirectUrl = `https://${baseDomain}${event.path}`;
|
|
34
33
|
}
|
|
35
34
|
|
|
35
|
+
// Add query parameters if they exist
|
|
36
|
+
const queryParams = event.queryStringParameters;
|
|
37
|
+
if (queryParams) {
|
|
38
|
+
const queryString = Object.entries(queryParams)
|
|
39
|
+
.filter(([, value]) => value !== undefined) // Filter out undefined values
|
|
40
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value as string)}`)
|
|
41
|
+
.join('&');
|
|
42
|
+
redirectUrl += `?${queryString}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
return {
|
|
37
46
|
statusCode: 301,
|
|
38
47
|
body: '',
|