@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.2
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 +69 -39
- package/package.json +3 -3
- package/src/cdk-constructs/IxNextjsSite.ts +5 -2
- package/src/lib/site/support.ts +121 -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,18 +69,33 @@ 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
|
+
console.log("updatedProps.cdk", updatedProps.cdk);
|
|
74
75
|
if (!updatedProps.cdk?.server || !("vpc" in updatedProps.cdk.server)) {
|
|
76
|
+
console.log("adding vpc for default server");
|
|
75
77
|
updatedProps.cdk = updatedProps.cdk ?? {};
|
|
76
78
|
updatedProps.cdk.server = {
|
|
77
79
|
...updatedProps.cdk.server,
|
|
78
80
|
vpc: vpcDetails.vpc,
|
|
79
81
|
};
|
|
80
|
-
|
|
82
|
+
if (!ixDeployConfig.vpcHttpProxy) {
|
|
83
|
+
console.warn(`Attempting to add HTTP proxy environment variables to ${id} but the VPC_HTTP_PROXY env var is not configured.`);
|
|
84
|
+
}
|
|
85
|
+
// If we're using the AWS runner then the build stage will already be inside the VPC and required the proxy but
|
|
86
|
+
// the HTTP proxy environment variables will be already set in the environment by the pipeline and so the build
|
|
87
|
+
// stage will inherit that.
|
|
88
|
+
updatedProps.environment = {
|
|
89
|
+
HTTP_PROXY: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
90
|
+
HTTPS_PROXY: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
91
|
+
http_proxy: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
92
|
+
https_proxy: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
93
|
+
...updatedProps.environment,
|
|
94
|
+
};
|
|
81
95
|
}
|
|
82
96
|
if (!updatedProps.cdk?.revalidation ||
|
|
83
97
|
!("vpc" in updatedProps.cdk.revalidation)) {
|
|
98
|
+
console.log("adding vpc for revalidation server");
|
|
84
99
|
updatedProps.cdk = props.cdk ?? {};
|
|
85
100
|
updatedProps.cdk.revalidation = {
|
|
86
101
|
...updatedProps.cdk.revalidation,
|
|
@@ -90,63 +105,78 @@ export function setupVpcDetails(scope, id, props) {
|
|
|
90
105
|
return updatedProps;
|
|
91
106
|
}
|
|
92
107
|
/**
|
|
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.
|
|
108
|
+
* Ensures environment variables that are conditionally included for buildtime or runtime are only used during the
|
|
109
|
+
* appropriate phase.
|
|
97
110
|
*/
|
|
98
|
-
export function
|
|
111
|
+
export function applyConditionalEnvironmentVariables(scope, id, props) {
|
|
99
112
|
const updatedProps = { ...props };
|
|
113
|
+
if (!updatedProps.environment)
|
|
114
|
+
return updatedProps;
|
|
115
|
+
const buildtimeSpecificEnvVars = Object.fromEntries(Object.entries(updatedProps.environment)
|
|
116
|
+
.filter(([, value]) => typeof value === "object")
|
|
117
|
+
.map(([varName, value]) => [
|
|
118
|
+
varName,
|
|
119
|
+
typeof value === "object" && "buildtime" in value
|
|
120
|
+
? value.buildtime
|
|
121
|
+
: undefined,
|
|
122
|
+
]));
|
|
123
|
+
const runtimeSpecificEnvVars = Object.fromEntries(Object.entries(updatedProps.environment)
|
|
124
|
+
.filter(([, value]) => typeof value === "object")
|
|
125
|
+
.map(([varName, value]) => [
|
|
126
|
+
varName,
|
|
127
|
+
typeof value === "object" && "runtime" in value
|
|
128
|
+
? value.runtime
|
|
129
|
+
: undefined,
|
|
130
|
+
]));
|
|
131
|
+
// Remove runtime excluded env vars from lambda
|
|
100
132
|
updatedProps.cdk = updatedProps.cdk ?? {};
|
|
101
133
|
const oldTransform = updatedProps.cdk.transform;
|
|
102
134
|
updatedProps.cdk.transform = (plan) => {
|
|
103
135
|
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
136
|
for (const origin of Object.values(plan.origins)) {
|
|
117
137
|
if (!("function" in origin) || !origin.function.environment) {
|
|
118
138
|
continue;
|
|
119
139
|
}
|
|
120
|
-
Object.
|
|
140
|
+
for (const [envVarName, envVarValue] of Object.entries(runtimeSpecificEnvVars)) {
|
|
141
|
+
if (envVarValue !== undefined) {
|
|
142
|
+
origin.function.environment[envVarName] = envVarValue;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
delete origin.function.environment[envVarName];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
121
148
|
}
|
|
122
149
|
};
|
|
150
|
+
// Remove buildtime excluded env vars from environment object which is used during build
|
|
151
|
+
for (const [envVarName, envVarValue] of Object.entries(buildtimeSpecificEnvVars)) {
|
|
152
|
+
if (envVarValue !== undefined) {
|
|
153
|
+
updatedProps.environment[envVarName] = envVarValue;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
delete updatedProps.environment[envVarName];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
123
159
|
return updatedProps;
|
|
124
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Before props reach this function they should have already been converted into something compatible with the parent
|
|
163
|
+
* SST construct. This function verifies that's the case and updates the type if so.
|
|
164
|
+
*/
|
|
165
|
+
export function parentCompatibleSsrProps(props) {
|
|
166
|
+
for (const value of Object.values(props.environment ?? {})) {
|
|
167
|
+
if (typeof value !== "string") {
|
|
168
|
+
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.");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return props;
|
|
172
|
+
}
|
|
125
173
|
export function setupDefaultEnvVars(scope, id, props) {
|
|
126
|
-
|
|
174
|
+
const updatedProps = { ...props };
|
|
127
175
|
// NextjsSite functions to not use default env var unfortunately so we have to
|
|
128
176
|
// explicitly set them ourselves https://github.com/sst/sst/issues/2359
|
|
129
177
|
if ("defaultFunctionProps" in scope) {
|
|
130
178
|
for (const funcProps of scope.defaultFunctionProps) {
|
|
131
179
|
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
180
|
updatedProps.environment = {
|
|
151
181
|
...defaultFunctionEnvVars,
|
|
152
182
|
...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.2",
|
|
3
|
+
"version": "2.9.0-internal-testing-set-http-proxy-env-var-2.2",
|
|
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,20 +140,39 @@ 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");
|
|
145
|
+
console.log("updatedProps.cdk", updatedProps.cdk);
|
|
118
146
|
if (!updatedProps.cdk?.server || !("vpc" in updatedProps.cdk.server)) {
|
|
147
|
+
console.log("adding vpc for default server");
|
|
119
148
|
updatedProps.cdk = updatedProps.cdk ?? {};
|
|
120
149
|
updatedProps.cdk.server = {
|
|
121
150
|
...updatedProps.cdk.server,
|
|
122
151
|
vpc: vpcDetails.vpc,
|
|
123
152
|
};
|
|
124
|
-
|
|
153
|
+
|
|
154
|
+
if (!ixDeployConfig.vpcHttpProxy) {
|
|
155
|
+
console.warn(
|
|
156
|
+
`Attempting to add HTTP proxy environment variables to ${id} but the VPC_HTTP_PROXY env var is not configured.`,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// If we're using the AWS runner then the build stage will already be inside the VPC and required the proxy but
|
|
161
|
+
// the HTTP proxy environment variables will be already set in the environment by the pipeline and so the build
|
|
162
|
+
// stage will inherit that.
|
|
163
|
+
updatedProps.environment = {
|
|
164
|
+
HTTP_PROXY: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
165
|
+
HTTPS_PROXY: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
166
|
+
http_proxy: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
167
|
+
https_proxy: { runtime: ixDeployConfig.vpcHttpProxy },
|
|
168
|
+
...updatedProps.environment,
|
|
169
|
+
};
|
|
125
170
|
}
|
|
126
171
|
if (
|
|
127
172
|
!updatedProps.cdk?.revalidation ||
|
|
128
173
|
!("vpc" in updatedProps.cdk.revalidation)
|
|
129
174
|
) {
|
|
175
|
+
console.log("adding vpc for revalidation server");
|
|
130
176
|
updatedProps.cdk = props.cdk ?? {};
|
|
131
177
|
updatedProps.cdk.revalidation = {
|
|
132
178
|
...updatedProps.cdk.revalidation,
|
|
@@ -137,86 +183,106 @@ export function setupVpcDetails<Props extends ExtendedNextjsSiteProps>(
|
|
|
137
183
|
}
|
|
138
184
|
|
|
139
185
|
/**
|
|
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.
|
|
186
|
+
* Ensures environment variables that are conditionally included for buildtime or runtime are only used during the
|
|
187
|
+
* appropriate phase.
|
|
144
188
|
*/
|
|
145
|
-
export function
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
props: Readonly<Props>,
|
|
149
|
-
proxyEnvVars?: Record<string, string>,
|
|
150
|
-
): Props {
|
|
189
|
+
export function applyConditionalEnvironmentVariables<
|
|
190
|
+
Props extends ExtendedNextjsSiteProps,
|
|
191
|
+
>(scope: Construct, id: string, props: Readonly<Props>): Props {
|
|
151
192
|
const updatedProps: Props = { ...props };
|
|
152
193
|
|
|
194
|
+
if (!updatedProps.environment) return updatedProps;
|
|
195
|
+
|
|
196
|
+
const buildtimeSpecificEnvVars = Object.fromEntries(
|
|
197
|
+
Object.entries(updatedProps.environment)
|
|
198
|
+
.filter(([, value]) => typeof value === "object")
|
|
199
|
+
.map(([varName, value]) => [
|
|
200
|
+
varName,
|
|
201
|
+
typeof value === "object" && "buildtime" in value
|
|
202
|
+
? value.buildtime
|
|
203
|
+
: undefined,
|
|
204
|
+
]),
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
const runtimeSpecificEnvVars = Object.fromEntries(
|
|
208
|
+
Object.entries(updatedProps.environment)
|
|
209
|
+
.filter(([, value]) => typeof value === "object")
|
|
210
|
+
.map(([varName, value]) => [
|
|
211
|
+
varName,
|
|
212
|
+
typeof value === "object" && "runtime" in value
|
|
213
|
+
? value.runtime
|
|
214
|
+
: undefined,
|
|
215
|
+
]),
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
// Remove runtime excluded env vars from lambda
|
|
153
219
|
updatedProps.cdk = updatedProps.cdk ?? {};
|
|
154
220
|
const oldTransform = updatedProps.cdk.transform;
|
|
155
221
|
updatedProps.cdk.transform = (plan: SSTPlan) => {
|
|
156
222
|
oldTransform?.(plan);
|
|
157
223
|
|
|
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
224
|
for (const origin of Object.values(plan.origins)) {
|
|
175
225
|
if (!("function" in origin) || !origin.function.environment) {
|
|
176
226
|
continue;
|
|
177
227
|
}
|
|
178
|
-
Object.
|
|
228
|
+
for (const [envVarName, envVarValue] of Object.entries(
|
|
229
|
+
runtimeSpecificEnvVars,
|
|
230
|
+
)) {
|
|
231
|
+
if (envVarValue !== undefined) {
|
|
232
|
+
origin.function.environment[envVarName] = envVarValue;
|
|
233
|
+
} else {
|
|
234
|
+
delete origin.function.environment[envVarName];
|
|
235
|
+
}
|
|
236
|
+
}
|
|
179
237
|
}
|
|
180
238
|
};
|
|
239
|
+
|
|
240
|
+
// Remove buildtime excluded env vars from environment object which is used during build
|
|
241
|
+
for (const [envVarName, envVarValue] of Object.entries(
|
|
242
|
+
buildtimeSpecificEnvVars,
|
|
243
|
+
)) {
|
|
244
|
+
if (envVarValue !== undefined) {
|
|
245
|
+
updatedProps.environment[envVarName] = envVarValue;
|
|
246
|
+
} else {
|
|
247
|
+
delete updatedProps.environment[envVarName];
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
181
251
|
return updatedProps;
|
|
182
252
|
}
|
|
183
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Before props reach this function they should have already been converted into something compatible with the parent
|
|
256
|
+
* SST construct. This function verifies that's the case and updates the type if so.
|
|
257
|
+
*/
|
|
258
|
+
export function parentCompatibleSsrProps<
|
|
259
|
+
Props extends ExtendedNextjsSiteProps,
|
|
260
|
+
ResultProps = Omit<Props, "environment"> & {
|
|
261
|
+
environment?: Record<string, string>;
|
|
262
|
+
},
|
|
263
|
+
>(props: Readonly<Props>): ResultProps {
|
|
264
|
+
for (const value of Object.values(props.environment ?? {})) {
|
|
265
|
+
if (typeof value !== "string") {
|
|
266
|
+
throw new Error(
|
|
267
|
+
"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.",
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return props as ResultProps;
|
|
272
|
+
}
|
|
273
|
+
|
|
184
274
|
export function setupDefaultEnvVars<Props extends ExtendedNextjsSiteProps>(
|
|
185
275
|
scope: Construct | Stack,
|
|
186
276
|
id: string,
|
|
187
277
|
props: Readonly<Props>,
|
|
188
278
|
): Props {
|
|
189
|
-
|
|
279
|
+
const updatedProps: Props = { ...props };
|
|
190
280
|
// NextjsSite functions to not use default env var unfortunately so we have to
|
|
191
281
|
// explicitly set them ourselves https://github.com/sst/sst/issues/2359
|
|
192
282
|
if ("defaultFunctionProps" in scope) {
|
|
193
283
|
for (const funcProps of scope.defaultFunctionProps) {
|
|
194
284
|
const defaultFunctionEnvVars = { ...funcProps.environment };
|
|
195
285
|
|
|
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
286
|
updatedProps.environment = {
|
|
221
287
|
...defaultFunctionEnvVars,
|
|
222
288
|
...updatedProps.environment,
|