@infoxchange/make-it-so 2.9.0-internal-testing-set-http-proxy-env-var.2 → 2.9.0-internal-testing-set-http-proxy-env-var-2.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/README.md +13 -11
- package/dist/cdk-constructs/IxNextjsSite.d.ts.map +1 -1
- package/dist/cdk-constructs/IxNextjsSite.js +4 -3
- package/dist/lib/site/support.d.ts +34 -6
- package/dist/lib/site/support.d.ts.map +1 -1
- package/dist/lib/site/support.js +63 -39
- package/package.json +3 -3
- package/src/cdk-constructs/IxNextjsSite.ts +5 -2
- package/src/lib/site/support.ts +115 -55
package/README.md
CHANGED
|
@@ -59,9 +59,10 @@ if (deployConfig.isIxDeploy) {
|
|
|
59
59
|
<details>
|
|
60
60
|
<summary><strong>IxNextjsSite</strong> - Deploys a serverless instance of a Next.js.</summary>
|
|
61
61
|
|
|
62
|
-
IxNextjsSite extends [SST's NextjsSite](https://v2.sst.dev/constructs/NextjsSite)
|
|
62
|
+
IxNextjsSite extends [SST's NextjsSite](https://v2.sst.dev/constructs/NextjsSite) with a few minor changes to the props
|
|
63
|
+
and behaviour.
|
|
63
64
|
|
|
64
|
-
If the
|
|
65
|
+
If the `customDomain` prop is not set then the first site domain provided by the IX deployment pipeline will be used as the primary custom domain, any additional domains (if there are any) will be used as alternative domain names and the first pipeline provided domain alias domain will be used will be used as a domain alias. This behaviour of setting pipeline configuring custom domains can be avoided by providing a value for `customDomain` (including explicitly setting it to `undefined` which will ensure no customDomain is used).
|
|
65
66
|
|
|
66
67
|
If `isIxManagedDomain` is true (which is the case if `customDomain` is set automatically using pipeline provided values) and no custom certificate is given then one will be created for any custom domains given (including alternative domain names which the base SST construct doesn't currently do).
|
|
67
68
|
|
|
@@ -71,16 +72,17 @@ It will also automatically attach the site to the standard IX VPC created in eac
|
|
|
71
72
|
explicitly pass other VPC details or set the VPC-related props (see the SST doco) to `undefined`) and set the env vars
|
|
72
73
|
`HTTP_PROXY`, `http_proxy`, `HTTPS_PROXY` and `https_proxy` to the HTTP Proxy for the VPC.
|
|
73
74
|
|
|
74
|
-
Unlike
|
|
75
|
+
Unlike [NextjsSite](https://v2.sst.dev/constructs/NextjsSite), any environment variables set with `stackOrApp.setDefaultFunctionProps()` or
|
|
75
76
|
`stackOrApp.addDefaultFunctionEnv()` will be inherited by the IxNextjsSite lambda functions.
|
|
76
77
|
|
|
77
78
|
#### Options:
|
|
78
79
|
|
|
79
|
-
| Prop | Type
|
|
80
|
-
| ------------------------------------ |
|
|
81
|
-
| [...NextjsSiteProps] |
|
|
82
|
-
| customDomain.isIxManagedDomain | boolean
|
|
83
|
-
| customDomain.additionalDomainAliases | string[]
|
|
80
|
+
| Prop | Type | Description |
|
|
81
|
+
| ------------------------------------ | ---------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
82
|
+
| [...NextjsSiteProps] | | Any props accepted by [SST's NextjsSite](https://v2.sst.dev/constructs/NextjsSite) |
|
|
83
|
+
| customDomain.isIxManagedDomain | boolean | (optional) If true will attempt to create DNS records and certs for it using the IX shared infra. Only required if explicitly setting customDomains and you want DNS records + certs setup for them |
|
|
84
|
+
| customDomain.additionalDomainAliases | string[] | (optional) Works like `customDomain.domainAlias` but `domainAlias` only allows one domain, additionalDomainAliases allows setting additional domains |
|
|
85
|
+
| environment | Record<string, string \| {buildtime?: string, runtime?: string}> | (optional) As well as accepting strings for environment variable values as is already done by [NextjsSite](https://v2.sst.dev/constructs/NextjsSite) it also accepts an object with the properties `buildtime` and/or `runtime` which allows you to customise the environment variable value during those different steps. |
|
|
84
86
|
|
|
85
87
|
```typescript
|
|
86
88
|
import { IxNextjsSite } from "@infoxchange/make-it-so/cdk-constructs";
|
|
@@ -90,7 +92,7 @@ const site = new IxNextjsSite(stack, "Site", {
|
|
|
90
92
|
DATABASE_URL: process.env.DATABASE_URL || "",
|
|
91
93
|
SESSION_SECRET: process.env.SESSION_SECRET || "",
|
|
92
94
|
},
|
|
93
|
-
//
|
|
95
|
+
// The default behaviour is the same as if you included:
|
|
94
96
|
// customDomain: {
|
|
95
97
|
// domainName: ixDeployConfig.siteDomains[0],
|
|
96
98
|
// alternateNames: ixDeployConfig.siteDomains.slice(1)
|
|
@@ -126,7 +128,7 @@ const site = new IxStaticSite(stack, "Site", {
|
|
|
126
128
|
environment: {
|
|
127
129
|
DOOHICKEY_NAME: process.env.DOOHICKEY_NAME || "",
|
|
128
130
|
},
|
|
129
|
-
//
|
|
131
|
+
// The default behaviour is the same as if you included:
|
|
130
132
|
// customDomain: {
|
|
131
133
|
// domainName: ixDeployConfig.siteDomains[0],
|
|
132
134
|
// alternateNames: ixDeployConfig.siteDomains.slice(1)
|
|
@@ -147,7 +149,7 @@ It will automatically create certificates and DNS records for a single domain th
|
|
|
147
149
|
import { IxApi } from "@infoxchange/make-it-so/cdk-constructs";
|
|
148
150
|
|
|
149
151
|
const site = new IxApi(stack, "api", {
|
|
150
|
-
//
|
|
152
|
+
// The default behaviour is the same as if you included:
|
|
151
153
|
// customDomain: {
|
|
152
154
|
// domainName: ixDeployConfig.siteDomains[0],
|
|
153
155
|
// },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IxNextjsSite.d.ts","sourceRoot":"","sources":["../../src/cdk-constructs/IxNextjsSite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EACL,KAAK,uBAAuB,
|
|
1
|
+
{"version":3,"file":"IxNextjsSite.d.ts","sourceRoot":"","sources":["../../src/cdk-constructs/IxNextjsSite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EACL,KAAK,uBAAuB,EAe7B,MAAM,wBAAwB,CAAC;AAEhC,KAAK,cAAc,GAAG,qBAAqB,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,KAAK,WAAW,GAAG,qBAAqB,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/D,KAAK,cAAc,GAAG,uBAAuB,CAAC;AAE9C,qBAAa,YAAa,SAAQ,UAAU;gBAExC,KAAK,EAAE,cAAc,EACrB,EAAE,EAAE,WAAW,EACf,KAAK,GAAE,cAAmB;IAkB5B,IAAW,aAAa,IAAI,MAAM,EAAE,CAEnC;IAED,IAAW,mBAAmB,IAAI,MAAM,GAAG,IAAI,CAE9C;IAED,IAAW,WAAW,IAAI,MAAM,GAAG,IAAI,CAEtC;IAED,IAAW,kBAAkB,IAAI,MAAM,EAAE,CAExC;IAED,IAAW,aAAa,IAAI,MAAM,GAAG,IAAI,CAExC;IAED,IAAW,aAAa,IAAI,MAAM,GAAG,IAAI,CAExC;CACF"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { NextjsSite } from "sst/constructs";
|
|
2
2
|
import ixDeployConfig from "../deployConfig.js";
|
|
3
|
-
import { getAliasDomain, getAlternativeDomains, getCustomDomains, getPrimaryCustomDomain, getPrimaryDomain, getPrimaryOrigin, setupCertificate, setupCustomDomain, setupDnsRecords, setupDomainAliasRedirect, setupVpcDetails, setupDefaultEnvVars, } from "../lib/site/support.js";
|
|
3
|
+
import { getAliasDomain, getAlternativeDomains, getCustomDomains, getPrimaryCustomDomain, getPrimaryDomain, getPrimaryOrigin, setupCertificate, setupCustomDomain, setupDnsRecords, setupDomainAliasRedirect, setupVpcDetails, setupDefaultEnvVars, applyConditionalEnvironmentVariables, parentCompatibleSsrProps, } from "../lib/site/support.js";
|
|
4
4
|
export class IxNextjsSite extends NextjsSite {
|
|
5
5
|
constructor(scope, id, props = {}) {
|
|
6
6
|
if (ixDeployConfig.isIxDeploy) {
|
|
7
|
-
props = setupDefaultEnvVars(scope, id, props);
|
|
8
7
|
props = setupVpcDetails(scope, id, props);
|
|
9
8
|
props = setupCustomDomain(scope, id, props);
|
|
10
9
|
props = setupCertificate(scope, id, props);
|
|
11
10
|
props = setupDomainAliasRedirect(scope, id, props);
|
|
12
11
|
}
|
|
13
|
-
|
|
12
|
+
props = setupDefaultEnvVars(scope, id, props);
|
|
13
|
+
props = applyConditionalEnvironmentVariables(scope, id, props);
|
|
14
|
+
super(scope, id, parentCompatibleSsrProps(props));
|
|
14
15
|
if (ixDeployConfig.isIxDeploy) {
|
|
15
16
|
setupDnsRecords(this, scope, id, props);
|
|
16
17
|
}
|
|
@@ -5,8 +5,31 @@ export type ExtendedCustomDomains = DistributionDomainProps & {
|
|
|
5
5
|
isIxManagedDomain?: boolean;
|
|
6
6
|
additionalDomainAliases?: string[];
|
|
7
7
|
};
|
|
8
|
-
export type ExtendedNextjsSiteProps = Omit<NextjsSiteProps, "customDomain"> & {
|
|
8
|
+
export type ExtendedNextjsSiteProps = Omit<NextjsSiteProps, "customDomain" | "environment"> & {
|
|
9
9
|
customDomain?: string | ExtendedCustomDomains;
|
|
10
|
+
/**
|
|
11
|
+
* An object with the key being the environment variable name. The value can either be the environment variable value
|
|
12
|
+
* as a string or as an object with `buildtime` and/or `runtime` properties where the values of `buildtime` and
|
|
13
|
+
* `runtime` is the environment variable value that will be used during that step.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```js
|
|
17
|
+
* environment: {
|
|
18
|
+
* USER_POOL_CLIENT: auth.cognitoUserPoolClient.userPoolClientId,
|
|
19
|
+
* NODE_OPTIONS: {
|
|
20
|
+
* buildtime: "--max-old-space-size=4096",
|
|
21
|
+
* },
|
|
22
|
+
* API_URL: {
|
|
23
|
+
* buildtime: "https://external.domain",
|
|
24
|
+
* runtime: "https://internal.domain",
|
|
25
|
+
* },
|
|
26
|
+
* },
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
environment?: Record<string, string | {
|
|
30
|
+
buildtime?: string;
|
|
31
|
+
runtime?: string;
|
|
32
|
+
}>;
|
|
10
33
|
};
|
|
11
34
|
export type ExtendedStaticSiteProps = Omit<StaticSiteProps, "customDomain"> & {
|
|
12
35
|
customDomain?: string | ExtendedCustomDomains;
|
|
@@ -16,12 +39,17 @@ export declare function setupCertificate<Props extends ExtendedStaticSiteProps |
|
|
|
16
39
|
export declare function setupDomainAliasRedirect<Props extends ExtendedStaticSiteProps | ExtendedNextjsSiteProps>(scope: Construct, id: string, props: Readonly<Props>): Props;
|
|
17
40
|
export declare function setupVpcDetails<Props extends ExtendedNextjsSiteProps>(scope: Construct, id: string, props: Readonly<Props>): Props;
|
|
18
41
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* We can't simply add them to `props.environment` because those are used during the build step which may happen outside
|
|
22
|
-
* the vpc. Instead we have to add them to all the places `props.environment` is used, accept for the build step.
|
|
42
|
+
* Ensures environment variables that are conditionally included for buildtime or runtime are only used during the
|
|
43
|
+
* appropriate phase.
|
|
23
44
|
*/
|
|
24
|
-
export declare function
|
|
45
|
+
export declare function applyConditionalEnvironmentVariables<Props extends ExtendedNextjsSiteProps>(scope: Construct, id: string, props: Readonly<Props>): Props;
|
|
46
|
+
/**
|
|
47
|
+
* Before props reach this function they should have already been converted into something compatible with the parent
|
|
48
|
+
* SST construct. This function verifies that's the case and updates the type if so.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parentCompatibleSsrProps<Props extends ExtendedNextjsSiteProps, ResultProps = Omit<Props, "environment"> & {
|
|
51
|
+
environment?: Record<string, string>;
|
|
52
|
+
}>(props: Readonly<Props>): ResultProps;
|
|
25
53
|
export declare function setupDefaultEnvVars<Props extends ExtendedNextjsSiteProps>(scope: Construct | Stack, id: string, props: Readonly<Props>): Props;
|
|
26
54
|
export declare function setupDnsRecords<Instance extends NextjsSite | StaticSite, Props extends ExtendedStaticSiteProps | ExtendedNextjsSiteProps>(instance: Instance, scope: Construct, id: string, props: Readonly<Props>): void;
|
|
27
55
|
export declare function getCustomDomains<Props extends ExtendedStaticSiteProps | ExtendedNextjsSiteProps>(props: Readonly<Props>): string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"support.d.ts","sourceRoot":"","sources":["../../../src/lib/site/support.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EACL,UAAU,EACV,eAAe,EACf,KAAK,EACL,UAAU,EACV,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAQxB,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAG9E,MAAM,MAAM,qBAAqB,GAAG,uBAAuB,GAAG;IAC5D,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC;CACpC,CAAC;AACF,MAAM,MAAM,uBAAuB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"support.d.ts","sourceRoot":"","sources":["../../../src/lib/site/support.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EACL,UAAU,EACV,eAAe,EACf,KAAK,EACL,UAAU,EACV,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAQxB,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAG9E,MAAM,MAAM,qBAAqB,GAAG,uBAAuB,GAAG;IAC5D,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC;CACpC,CAAC;AACF,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACxC,eAAe,EACf,cAAc,GAAG,aAAa,CAC/B,GAAG;IACF,YAAY,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAAC;IAC9C;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAAW,CAAC,EAAE,MAAM,CAClB,MAAM,EACN,MAAM,GAAG;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAClD,CAAC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,GAAG,IAAI,CAKvC;AAED,wBAAgB,qBAAqB,CACnC,KAAK,SAAS,uBAAuB,GAAG,uBAAuB,EAC/D,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,MAAM,EAAE,CAKlC"}
|
package/dist/lib/site/support.js
CHANGED
|
@@ -69,7 +69,7 @@ export function setupDomainAliasRedirect(scope, id, props) {
|
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
export function setupVpcDetails(scope, id, props) {
|
|
72
|
-
|
|
72
|
+
const updatedProps = { ...props };
|
|
73
73
|
const vpcDetails = new IxVpcDetails(scope, id + "-IxVpcDetails");
|
|
74
74
|
if (!updatedProps.cdk?.server || !("vpc" in updatedProps.cdk.server)) {
|
|
75
75
|
updatedProps.cdk = updatedProps.cdk ?? {};
|
|
@@ -77,7 +77,16 @@ export function setupVpcDetails(scope, id, props) {
|
|
|
77
77
|
...updatedProps.cdk.server,
|
|
78
78
|
vpc: vpcDetails.vpc,
|
|
79
79
|
};
|
|
80
|
-
|
|
80
|
+
if (!ixDeployConfig.vpcHttpProxy) {
|
|
81
|
+
console.warn(`Attempting to add HTTP proxy environment variables to ${id} but the VPC_HTTP_PROXY env var is not configured.`);
|
|
82
|
+
}
|
|
83
|
+
updatedProps.environment = {
|
|
84
|
+
HTTP_PROXY: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
85
|
+
HTTPS_PROXY: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
86
|
+
http_proxy: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
87
|
+
https_proxy: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
88
|
+
...updatedProps.environment,
|
|
89
|
+
};
|
|
81
90
|
}
|
|
82
91
|
if (!updatedProps.cdk?.revalidation ||
|
|
83
92
|
!("vpc" in updatedProps.cdk.revalidation)) {
|
|
@@ -90,63 +99,78 @@ export function setupVpcDetails(scope, id, props) {
|
|
|
90
99
|
return updatedProps;
|
|
91
100
|
}
|
|
92
101
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* We can't simply add them to `props.environment` because those are used during the build step which may happen outside
|
|
96
|
-
* the vpc. Instead we have to add them to all the places `props.environment` is used, accept for the build step.
|
|
102
|
+
* Ensures environment variables that are conditionally included for buildtime or runtime are only used during the
|
|
103
|
+
* appropriate phase.
|
|
97
104
|
*/
|
|
98
|
-
export function
|
|
105
|
+
export function applyConditionalEnvironmentVariables(scope, id, props) {
|
|
99
106
|
const updatedProps = { ...props };
|
|
107
|
+
if (!updatedProps.environment)
|
|
108
|
+
return updatedProps;
|
|
109
|
+
const buildtimeSpecificEnvVars = Object.fromEntries(Object.entries(updatedProps.environment)
|
|
110
|
+
.filter(([, value]) => typeof value === "object")
|
|
111
|
+
.map(([varName, value]) => [
|
|
112
|
+
varName,
|
|
113
|
+
typeof value === "object" && "buildtime" in value
|
|
114
|
+
? value.buildtime
|
|
115
|
+
: undefined,
|
|
116
|
+
]));
|
|
117
|
+
const runtimeSpecificEnvVars = Object.fromEntries(Object.entries(updatedProps.environment)
|
|
118
|
+
.filter(([, value]) => typeof value === "object")
|
|
119
|
+
.map(([varName, value]) => [
|
|
120
|
+
varName,
|
|
121
|
+
typeof value === "object" && "runtime" in value
|
|
122
|
+
? value.runtime
|
|
123
|
+
: undefined,
|
|
124
|
+
]));
|
|
125
|
+
// Remove runtime excluded env vars from lambda
|
|
100
126
|
updatedProps.cdk = updatedProps.cdk ?? {};
|
|
101
127
|
const oldTransform = updatedProps.cdk.transform;
|
|
102
128
|
updatedProps.cdk.transform = (plan) => {
|
|
103
129
|
oldTransform?.(plan);
|
|
104
|
-
if (!proxyEnvVars) {
|
|
105
|
-
if (!ixDeployConfig.vpcHttpProxy) {
|
|
106
|
-
console.warn(`Attempting to add HTTP proxy environment variables to ${id} but the VPC_HTTP_PROXY env var is not configured.`);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
proxyEnvVars = {
|
|
110
|
-
HTTP_PROXY: ixDeployConfig.vpcHttpProxy,
|
|
111
|
-
HTTPS_PROXY: ixDeployConfig.vpcHttpProxy,
|
|
112
|
-
http_proxy: ixDeployConfig.vpcHttpProxy,
|
|
113
|
-
https_proxy: ixDeployConfig.vpcHttpProxy,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
130
|
for (const origin of Object.values(plan.origins)) {
|
|
117
131
|
if (!("function" in origin) || !origin.function.environment) {
|
|
118
132
|
continue;
|
|
119
133
|
}
|
|
120
|
-
Object.
|
|
134
|
+
for (const [envVarName, envVarValue] of Object.entries(runtimeSpecificEnvVars)) {
|
|
135
|
+
if (envVarValue !== undefined) {
|
|
136
|
+
origin.function.environment[envVarName] = envVarValue;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
delete origin.function.environment[envVarName];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
121
142
|
}
|
|
122
143
|
};
|
|
144
|
+
// Remove buildtime excluded env vars from environment object which is used during build
|
|
145
|
+
for (const [envVarName, envVarValue] of Object.entries(buildtimeSpecificEnvVars)) {
|
|
146
|
+
if (envVarValue !== undefined) {
|
|
147
|
+
updatedProps.environment[envVarName] = envVarValue;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
delete updatedProps.environment[envVarName];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
123
153
|
return updatedProps;
|
|
124
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Before props reach this function they should have already been converted into something compatible with the parent
|
|
157
|
+
* SST construct. This function verifies that's the case and updates the type if so.
|
|
158
|
+
*/
|
|
159
|
+
export function parentCompatibleSsrProps(props) {
|
|
160
|
+
for (const value of Object.values(props.environment ?? {})) {
|
|
161
|
+
if (typeof value !== "string") {
|
|
162
|
+
throw new Error("Internal make-it-so error: The environment prop contains buildtime/runtime specific environment variables which cannot be passed to the parent NextjsSite construct. Please use the applyConditionalEnvironmentVariables function to ensure only appropriate environment variables are included.");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return props;
|
|
166
|
+
}
|
|
125
167
|
export function setupDefaultEnvVars(scope, id, props) {
|
|
126
|
-
|
|
168
|
+
const updatedProps = { ...props };
|
|
127
169
|
// NextjsSite functions to not use default env var unfortunately so we have to
|
|
128
170
|
// explicitly set them ourselves https://github.com/sst/sst/issues/2359
|
|
129
171
|
if ("defaultFunctionProps" in scope) {
|
|
130
172
|
for (const funcProps of scope.defaultFunctionProps) {
|
|
131
173
|
const defaultFunctionEnvVars = { ...funcProps.environment };
|
|
132
|
-
// Remove any HTTP proxy related env vars and set them in a separate call to addHttpProxyEnvVars
|
|
133
|
-
// to avoid them being used during the build step.
|
|
134
|
-
const defaultFunctionHttpProxyEnvVars = {};
|
|
135
|
-
for (const proxyEnvVar of [
|
|
136
|
-
"HTTP_PROXY",
|
|
137
|
-
"HTTPS_PROXY",
|
|
138
|
-
"http_proxy",
|
|
139
|
-
"https_proxy",
|
|
140
|
-
]) {
|
|
141
|
-
if (proxyEnvVar in defaultFunctionEnvVars) {
|
|
142
|
-
defaultFunctionHttpProxyEnvVars[proxyEnvVar] =
|
|
143
|
-
defaultFunctionEnvVars[proxyEnvVar];
|
|
144
|
-
delete defaultFunctionEnvVars[proxyEnvVar];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (Object.keys(defaultFunctionHttpProxyEnvVars).length) {
|
|
148
|
-
updatedProps = addHttpProxyEnvVars(scope, id, updatedProps, defaultFunctionHttpProxyEnvVars);
|
|
149
|
-
}
|
|
150
174
|
updatedProps.environment = {
|
|
151
175
|
...defaultFunctionEnvVars,
|
|
152
176
|
...updatedProps.environment,
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infoxchange/make-it-so",
|
|
3
|
-
"version": "2.9.0-internal-testing-set-http-proxy-env-var.
|
|
3
|
+
"version": "2.9.0-internal-testing-set-http-proxy-env-var-2.1",
|
|
4
4
|
"description": "Makes deploying services to IX infra easy",
|
|
5
5
|
"repository": "github:infoxchange/make-it-so",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"test": "vitest",
|
|
10
|
-
"lint": "eslint . --fix && prettier . --write",
|
|
11
|
-
"lint:check": "eslint . && prettier . --check",
|
|
10
|
+
"lint": "eslint . --fix && prettier . --write && tsc --noEmit",
|
|
11
|
+
"lint:check": "eslint . && prettier . --check && tsc --noEmit",
|
|
12
12
|
"prepare": "husky",
|
|
13
13
|
"commit": "lint-staged && commit"
|
|
14
14
|
},
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
setupDomainAliasRedirect,
|
|
15
15
|
setupVpcDetails,
|
|
16
16
|
setupDefaultEnvVars,
|
|
17
|
+
applyConditionalEnvironmentVariables,
|
|
18
|
+
parentCompatibleSsrProps,
|
|
17
19
|
} from "../lib/site/support.js";
|
|
18
20
|
|
|
19
21
|
type ConstructScope = ConstructorParameters<typeof NextjsSite>[0];
|
|
@@ -27,14 +29,15 @@ export class IxNextjsSite extends NextjsSite {
|
|
|
27
29
|
props: ConstructProps = {},
|
|
28
30
|
) {
|
|
29
31
|
if (ixDeployConfig.isIxDeploy) {
|
|
30
|
-
props = setupDefaultEnvVars(scope, id, props);
|
|
31
32
|
props = setupVpcDetails(scope, id, props);
|
|
32
33
|
props = setupCustomDomain(scope, id, props);
|
|
33
34
|
props = setupCertificate(scope, id, props);
|
|
34
35
|
props = setupDomainAliasRedirect(scope, id, props);
|
|
35
36
|
}
|
|
37
|
+
props = setupDefaultEnvVars(scope, id, props);
|
|
38
|
+
props = applyConditionalEnvironmentVariables(scope, id, props);
|
|
36
39
|
|
|
37
|
-
super(scope, id, props);
|
|
40
|
+
super(scope, id, parentCompatibleSsrProps(props));
|
|
38
41
|
|
|
39
42
|
if (ixDeployConfig.isIxDeploy) {
|
|
40
43
|
setupDnsRecords(this, scope, id, props);
|
package/src/lib/site/support.ts
CHANGED
|
@@ -20,9 +20,36 @@ export type ExtendedCustomDomains = DistributionDomainProps & {
|
|
|
20
20
|
isIxManagedDomain?: boolean;
|
|
21
21
|
additionalDomainAliases?: string[];
|
|
22
22
|
};
|
|
23
|
-
export type ExtendedNextjsSiteProps = Omit<
|
|
23
|
+
export type ExtendedNextjsSiteProps = Omit<
|
|
24
|
+
NextjsSiteProps,
|
|
25
|
+
"customDomain" | "environment"
|
|
26
|
+
> & {
|
|
24
27
|
customDomain?: string | ExtendedCustomDomains;
|
|
28
|
+
/**
|
|
29
|
+
* An object with the key being the environment variable name. The value can either be the environment variable value
|
|
30
|
+
* as a string or as an object with `buildtime` and/or `runtime` properties where the values of `buildtime` and
|
|
31
|
+
* `runtime` is the environment variable value that will be used during that step.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```js
|
|
35
|
+
* environment: {
|
|
36
|
+
* USER_POOL_CLIENT: auth.cognitoUserPoolClient.userPoolClientId,
|
|
37
|
+
* NODE_OPTIONS: {
|
|
38
|
+
* buildtime: "--max-old-space-size=4096",
|
|
39
|
+
* },
|
|
40
|
+
* API_URL: {
|
|
41
|
+
* buildtime: "https://external.domain",
|
|
42
|
+
* runtime: "https://internal.domain",
|
|
43
|
+
* },
|
|
44
|
+
* },
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
environment?: Record<
|
|
48
|
+
string,
|
|
49
|
+
string | { buildtime?: string; runtime?: string }
|
|
50
|
+
>;
|
|
25
51
|
};
|
|
52
|
+
|
|
26
53
|
export type ExtendedStaticSiteProps = Omit<StaticSiteProps, "customDomain"> & {
|
|
27
54
|
customDomain?: string | ExtendedCustomDomains;
|
|
28
55
|
};
|
|
@@ -113,7 +140,7 @@ export function setupVpcDetails<Props extends ExtendedNextjsSiteProps>(
|
|
|
113
140
|
id: string,
|
|
114
141
|
props: Readonly<Props>,
|
|
115
142
|
): Props {
|
|
116
|
-
|
|
143
|
+
const updatedProps: Props = { ...props };
|
|
117
144
|
const vpcDetails = new IxVpcDetails(scope, id + "-IxVpcDetails");
|
|
118
145
|
if (!updatedProps.cdk?.server || !("vpc" in updatedProps.cdk.server)) {
|
|
119
146
|
updatedProps.cdk = updatedProps.cdk ?? {};
|
|
@@ -121,7 +148,20 @@ export function setupVpcDetails<Props extends ExtendedNextjsSiteProps>(
|
|
|
121
148
|
...updatedProps.cdk.server,
|
|
122
149
|
vpc: vpcDetails.vpc,
|
|
123
150
|
};
|
|
124
|
-
|
|
151
|
+
|
|
152
|
+
if (!ixDeployConfig.vpcHttpProxy) {
|
|
153
|
+
console.warn(
|
|
154
|
+
`Attempting to add HTTP proxy environment variables to ${id} but the VPC_HTTP_PROXY env var is not configured.`,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
updatedProps.environment = {
|
|
159
|
+
HTTP_PROXY: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
160
|
+
HTTPS_PROXY: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
161
|
+
http_proxy: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
162
|
+
https_proxy: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
163
|
+
...updatedProps.environment,
|
|
164
|
+
};
|
|
125
165
|
}
|
|
126
166
|
if (
|
|
127
167
|
!updatedProps.cdk?.revalidation ||
|
|
@@ -137,86 +177,106 @@ export function setupVpcDetails<Props extends ExtendedNextjsSiteProps>(
|
|
|
137
177
|
}
|
|
138
178
|
|
|
139
179
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* We can't simply add them to `props.environment` because those are used during the build step which may happen outside
|
|
143
|
-
* the vpc. Instead we have to add them to all the places `props.environment` is used, accept for the build step.
|
|
180
|
+
* Ensures environment variables that are conditionally included for buildtime or runtime are only used during the
|
|
181
|
+
* appropriate phase.
|
|
144
182
|
*/
|
|
145
|
-
export function
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
props: Readonly<Props>,
|
|
149
|
-
proxyEnvVars?: Record<string, string>,
|
|
150
|
-
): Props {
|
|
183
|
+
export function applyConditionalEnvironmentVariables<
|
|
184
|
+
Props extends ExtendedNextjsSiteProps,
|
|
185
|
+
>(scope: Construct, id: string, props: Readonly<Props>): Props {
|
|
151
186
|
const updatedProps: Props = { ...props };
|
|
152
187
|
|
|
188
|
+
if (!updatedProps.environment) return updatedProps;
|
|
189
|
+
|
|
190
|
+
const buildtimeSpecificEnvVars = Object.fromEntries(
|
|
191
|
+
Object.entries(updatedProps.environment)
|
|
192
|
+
.filter(([, value]) => typeof value === "object")
|
|
193
|
+
.map(([varName, value]) => [
|
|
194
|
+
varName,
|
|
195
|
+
typeof value === "object" && "buildtime" in value
|
|
196
|
+
? value.buildtime
|
|
197
|
+
: undefined,
|
|
198
|
+
]),
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
const runtimeSpecificEnvVars = Object.fromEntries(
|
|
202
|
+
Object.entries(updatedProps.environment)
|
|
203
|
+
.filter(([, value]) => typeof value === "object")
|
|
204
|
+
.map(([varName, value]) => [
|
|
205
|
+
varName,
|
|
206
|
+
typeof value === "object" && "runtime" in value
|
|
207
|
+
? value.runtime
|
|
208
|
+
: undefined,
|
|
209
|
+
]),
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
// Remove runtime excluded env vars from lambda
|
|
153
213
|
updatedProps.cdk = updatedProps.cdk ?? {};
|
|
154
214
|
const oldTransform = updatedProps.cdk.transform;
|
|
155
215
|
updatedProps.cdk.transform = (plan: SSTPlan) => {
|
|
156
216
|
oldTransform?.(plan);
|
|
157
217
|
|
|
158
|
-
if (!proxyEnvVars) {
|
|
159
|
-
if (!ixDeployConfig.vpcHttpProxy) {
|
|
160
|
-
console.warn(
|
|
161
|
-
`Attempting to add HTTP proxy environment variables to ${id} but the VPC_HTTP_PROXY env var is not configured.`,
|
|
162
|
-
);
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
proxyEnvVars = {
|
|
167
|
-
HTTP_PROXY: ixDeployConfig.vpcHttpProxy,
|
|
168
|
-
HTTPS_PROXY: ixDeployConfig.vpcHttpProxy,
|
|
169
|
-
http_proxy: ixDeployConfig.vpcHttpProxy,
|
|
170
|
-
https_proxy: ixDeployConfig.vpcHttpProxy,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
218
|
for (const origin of Object.values(plan.origins)) {
|
|
175
219
|
if (!("function" in origin) || !origin.function.environment) {
|
|
176
220
|
continue;
|
|
177
221
|
}
|
|
178
|
-
Object.
|
|
222
|
+
for (const [envVarName, envVarValue] of Object.entries(
|
|
223
|
+
runtimeSpecificEnvVars,
|
|
224
|
+
)) {
|
|
225
|
+
if (envVarValue !== undefined) {
|
|
226
|
+
origin.function.environment[envVarName] = envVarValue;
|
|
227
|
+
} else {
|
|
228
|
+
delete origin.function.environment[envVarName];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
179
231
|
}
|
|
180
232
|
};
|
|
233
|
+
|
|
234
|
+
// Remove buildtime excluded env vars from environment object which is used during build
|
|
235
|
+
for (const [envVarName, envVarValue] of Object.entries(
|
|
236
|
+
buildtimeSpecificEnvVars,
|
|
237
|
+
)) {
|
|
238
|
+
if (envVarValue !== undefined) {
|
|
239
|
+
updatedProps.environment[envVarName] = envVarValue;
|
|
240
|
+
} else {
|
|
241
|
+
delete updatedProps.environment[envVarName];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
181
245
|
return updatedProps;
|
|
182
246
|
}
|
|
183
247
|
|
|
248
|
+
/**
|
|
249
|
+
* Before props reach this function they should have already been converted into something compatible with the parent
|
|
250
|
+
* SST construct. This function verifies that's the case and updates the type if so.
|
|
251
|
+
*/
|
|
252
|
+
export function parentCompatibleSsrProps<
|
|
253
|
+
Props extends ExtendedNextjsSiteProps,
|
|
254
|
+
ResultProps = Omit<Props, "environment"> & {
|
|
255
|
+
environment?: Record<string, string>;
|
|
256
|
+
},
|
|
257
|
+
>(props: Readonly<Props>): ResultProps {
|
|
258
|
+
for (const value of Object.values(props.environment ?? {})) {
|
|
259
|
+
if (typeof value !== "string") {
|
|
260
|
+
throw new Error(
|
|
261
|
+
"Internal make-it-so error: The environment prop contains buildtime/runtime specific environment variables which cannot be passed to the parent NextjsSite construct. Please use the applyConditionalEnvironmentVariables function to ensure only appropriate environment variables are included.",
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return props as ResultProps;
|
|
266
|
+
}
|
|
267
|
+
|
|
184
268
|
export function setupDefaultEnvVars<Props extends ExtendedNextjsSiteProps>(
|
|
185
269
|
scope: Construct | Stack,
|
|
186
270
|
id: string,
|
|
187
271
|
props: Readonly<Props>,
|
|
188
272
|
): Props {
|
|
189
|
-
|
|
273
|
+
const updatedProps: Props = { ...props };
|
|
190
274
|
// NextjsSite functions to not use default env var unfortunately so we have to
|
|
191
275
|
// explicitly set them ourselves https://github.com/sst/sst/issues/2359
|
|
192
276
|
if ("defaultFunctionProps" in scope) {
|
|
193
277
|
for (const funcProps of scope.defaultFunctionProps) {
|
|
194
278
|
const defaultFunctionEnvVars = { ...funcProps.environment };
|
|
195
279
|
|
|
196
|
-
// Remove any HTTP proxy related env vars and set them in a separate call to addHttpProxyEnvVars
|
|
197
|
-
// to avoid them being used during the build step.
|
|
198
|
-
const defaultFunctionHttpProxyEnvVars: Record<string, string> = {};
|
|
199
|
-
for (const proxyEnvVar of [
|
|
200
|
-
"HTTP_PROXY",
|
|
201
|
-
"HTTPS_PROXY",
|
|
202
|
-
"http_proxy",
|
|
203
|
-
"https_proxy",
|
|
204
|
-
]) {
|
|
205
|
-
if (proxyEnvVar in defaultFunctionEnvVars) {
|
|
206
|
-
defaultFunctionHttpProxyEnvVars[proxyEnvVar] =
|
|
207
|
-
defaultFunctionEnvVars[proxyEnvVar];
|
|
208
|
-
delete defaultFunctionEnvVars[proxyEnvVar];
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
if (Object.keys(defaultFunctionHttpProxyEnvVars).length) {
|
|
212
|
-
updatedProps = addHttpProxyEnvVars(
|
|
213
|
-
scope,
|
|
214
|
-
id,
|
|
215
|
-
updatedProps,
|
|
216
|
-
defaultFunctionHttpProxyEnvVars,
|
|
217
|
-
) as Props;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
280
|
updatedProps.environment = {
|
|
221
281
|
...defaultFunctionEnvVars,
|
|
222
282
|
...updatedProps.environment,
|