@infoxchange/make-it-so 2.8.1 → 2.9.0-internal-testing-set-http-proxy-env-var.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 CHANGED
@@ -67,7 +67,12 @@ If `isIxManagedDomain` is true (which is the case if `customDomain` is set autom
67
67
 
68
68
  Also if `isIxManagedDomain` is true DNS records will be automatically created for them.
69
69
 
70
- It will also automatically attach the site to the standard IX VPC created in each workload account (unless you explicitly pass other VPC details or set the VPC-related props (see the SST doco) to `undefined`).
70
+ It will also automatically attach the site to the standard IX VPC created in each workload account (unless you
71
+ explicitly pass other VPC details or set the VPC-related props (see the SST doco) to `undefined`) and set the env vars
72
+ `HTTP_PROXY`, `http_proxy`, `HTTPS_PROXY` and `https_proxy` to the HTTP Proxy for the VPC.
73
+
74
+ Unlike SST's NextjsSite, any environment variables set with `stackOrApp.setDefaultFunctionProps()` or
75
+ `stackOrApp.addDefaultFunctionEnv()` will be inherited by the IxNextjsSite lambda functions.
71
76
 
72
77
  #### Options:
73
78
 
@@ -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,EAY7B,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;IAgB5B,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
+ {"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,EAa7B,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;IAiB5B,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,9 +1,10 @@
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, } from "../lib/site/support.js";
3
+ import { getAliasDomain, getAlternativeDomains, getCustomDomains, getPrimaryCustomDomain, getPrimaryDomain, getPrimaryOrigin, setupCertificate, setupCustomDomain, setupDnsRecords, setupDomainAliasRedirect, setupVpcDetails, setupDefaultEnvVars, } 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);
7
8
  props = setupVpcDetails(scope, id, props);
8
9
  props = setupCustomDomain(scope, id, props);
9
10
  props = setupCertificate(scope, id, props);
@@ -14,6 +14,7 @@ declare const _default: {
14
14
  smtpHost: string;
15
15
  smtpPort: number;
16
16
  clamAVUrl: string;
17
+ vpcHttpProxy: string;
17
18
  } | {
18
19
  isIxDeploy: false;
19
20
  appName: string;
@@ -28,6 +29,7 @@ declare const _default: {
28
29
  deployTriggeredBy: string;
29
30
  smtpHost: string;
30
31
  clamAVUrl: string;
32
+ vpcHttpProxy: string;
31
33
  isInternalApp?: boolean | undefined;
32
34
  smtpPort?: number | undefined;
33
35
  };
@@ -1 +1 @@
1
- {"version":3,"file":"deployConfig.d.ts","sourceRoot":"","sources":["../src/deployConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EA,wBAAqC"}
1
+ {"version":3,"file":"deployConfig.d.ts","sourceRoot":"","sources":["../src/deployConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,wBAAqC"}
@@ -15,6 +15,7 @@ const envVars = {
15
15
  smtpHost: process.env.SMTP_HOST ?? "",
16
16
  smtpPort: process.env.SMTP_PORT ?? "",
17
17
  clamAVUrl: process.env.CLAMAV_URL ?? "",
18
+ vpcHttpProxy: process.env.VPC_HTTP_PROXY ?? "",
18
19
  };
19
20
  const ixDeployConfigSchema = z
20
21
  .object({
@@ -37,6 +38,7 @@ const ixDeployConfigSchema = z
37
38
  smtpHost: z.string().min(1),
38
39
  smtpPort: z.coerce.number().int(),
39
40
  clamAVUrl: z.string().url(),
41
+ vpcHttpProxy: z.string().url(),
40
42
  })
41
43
  .strip();
42
44
  const nonIxDeployConfigSchema = z
@@ -64,6 +66,7 @@ const nonIxDeployConfigSchema = z
64
66
  .string()
65
67
  .transform((val) => isNaN(parseInt(val, 10)) ? undefined : parseInt(val, 10)),
66
68
  clamAVUrl: z.string(),
69
+ vpcHttpProxy: z.string(),
67
70
  })
68
71
  .strip();
69
72
  const schema = z.discriminatedUnion("isIxDeploy", [
@@ -1,5 +1,5 @@
1
1
  import { Construct } from "constructs";
2
- import { NextjsSite, NextjsSiteProps, StaticSite, StaticSiteProps } from "sst/constructs";
2
+ import { NextjsSite, NextjsSiteProps, Stack, StaticSite, StaticSiteProps } from "sst/constructs";
3
3
  import { type DistributionDomainProps } from "sst/constructs/Distribution.js";
4
4
  export type ExtendedCustomDomains = DistributionDomainProps & {
5
5
  isIxManagedDomain?: boolean;
@@ -15,6 +15,14 @@ export declare function setupCustomDomain<Props extends ExtendedStaticSiteProps
15
15
  export declare function setupCertificate<Props extends ExtendedStaticSiteProps | ExtendedNextjsSiteProps>(scope: Construct, id: string, props: Readonly<Props>): Props;
16
16
  export declare function setupDomainAliasRedirect<Props extends ExtendedStaticSiteProps | ExtendedNextjsSiteProps>(scope: Construct, id: string, props: Readonly<Props>): Props;
17
17
  export declare function setupVpcDetails<Props extends ExtendedNextjsSiteProps>(scope: Construct, id: string, props: Readonly<Props>): Props;
18
+ /**
19
+ * Adds HTTP proxy environment variables to the provided site props.
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.
23
+ */
24
+ export declare function addHttpProxyEnvVars<Props extends ExtendedNextjsSiteProps>(scope: Construct, id: string, props: Readonly<Props>, proxyEnvVars?: Record<string, string>): Props;
25
+ export declare function setupDefaultEnvVars<Props extends ExtendedNextjsSiteProps>(scope: Construct | Stack, id: string, props: Readonly<Props>): Props;
18
26
  export declare function setupDnsRecords<Instance extends NextjsSite | StaticSite, Props extends ExtendedStaticSiteProps | ExtendedNextjsSiteProps>(instance: Instance, scope: Construct, id: string, props: Readonly<Props>): void;
19
27
  export declare function getCustomDomains<Props extends ExtendedStaticSiteProps | ExtendedNextjsSiteProps>(props: Readonly<Props>): string[];
20
28
  export declare function getPrimaryDomain<Instance extends NextjsSite | StaticSite, Props extends ExtendedStaticSiteProps | ExtendedNextjsSiteProps>(instance: Instance, props: Readonly<Props>): string | null;
@@ -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,UAAU,EACV,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAQxB,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAE9E,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,CAAC,eAAe,EAAE,cAAc,CAAC,GAAG;IAC5E,YAAY,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAAC;CAC/C,CAAC;AACF,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,eAAe,EAAE,cAAc,CAAC,GAAG;IAC5E,YAAY,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAAC;CAC/C,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,KAAK,SAAS,uBAAuB,GAAG,uBAAuB,EAC/D,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ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ACV,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GACrB,IAAI,CAmBN;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,SAAS,uBAAuB,GAAG,uBAAuB,EAC/D,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,MAAM,EAAE,CAWlC;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,SAAS,UAAU,GAAG,UAAU,EACxC,KAAK,SAAS,uBAAuB,GAAG,uBAAuB,EAC/D,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,MAAM,GAAG,IAAI,CAM3D;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,SAAS,UAAU,GAAG,UAAU,EACxC,KAAK,SAAS,uBAAuB,GAAG,uBAAuB,EAC/D,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,MAAM,GAAG,IAAI,CAG3D;AAED,wBAAgB,sBAAsB,CACpC,KAAK,SAAS,uBAAuB,GAAG,uBAAuB,EAC/D,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,MAAM,GAAG,IAAI,CAOvC;AAED,wBAAgB,cAAc,CAC5B,KAAK,SAAS,uBAAuB,GAAG,uBAAuB,EAC/D,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,MAAM,GAAG,IAAI,CAKvC;AAED,wBAAgB,qBAAqB,CACnC,KAAK,SAAS,uBAAuB,GAAG,uBAAuB,EAC/D,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,MAAM,EAAE,CAKlC"}
@@ -69,7 +69,7 @@ export function setupDomainAliasRedirect(scope, id, props) {
69
69
  };
70
70
  }
71
71
  export function setupVpcDetails(scope, id, props) {
72
- const updatedProps = { ...props };
72
+ let 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,6 +77,7 @@ export function setupVpcDetails(scope, id, props) {
77
77
  ...updatedProps.cdk.server,
78
78
  vpc: vpcDetails.vpc,
79
79
  };
80
+ updatedProps = addHttpProxyEnvVars(scope, id, updatedProps);
80
81
  }
81
82
  if (!updatedProps.cdk?.revalidation ||
82
83
  !("vpc" in updatedProps.cdk.revalidation)) {
@@ -88,6 +89,72 @@ export function setupVpcDetails(scope, id, props) {
88
89
  }
89
90
  return updatedProps;
90
91
  }
92
+ /**
93
+ * Adds HTTP proxy environment variables to the provided site props.
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.
97
+ */
98
+ export function addHttpProxyEnvVars(scope, id, props, proxyEnvVars) {
99
+ const updatedProps = { ...props };
100
+ updatedProps.cdk = updatedProps.cdk ?? {};
101
+ const oldTransform = updatedProps.cdk.transform;
102
+ updatedProps.cdk.transform = (plan) => {
103
+ 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
+ for (const origin of Object.values(plan.origins)) {
117
+ if (!("function" in origin) || !origin.function.environment) {
118
+ continue;
119
+ }
120
+ Object.assign(origin.function.environment, proxyEnvVars);
121
+ }
122
+ };
123
+ return updatedProps;
124
+ }
125
+ export function setupDefaultEnvVars(scope, id, props) {
126
+ let updatedProps = { ...props };
127
+ // NextjsSite functions to not use default env var unfortunately so we have to
128
+ // explicitly set them ourselves https://github.com/sst/sst/issues/2359
129
+ if ("defaultFunctionProps" in scope) {
130
+ for (const funcProps of scope.defaultFunctionProps) {
131
+ 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
+ updatedProps.environment = {
151
+ ...defaultFunctionEnvVars,
152
+ ...updatedProps.environment,
153
+ };
154
+ }
155
+ }
156
+ return updatedProps;
157
+ }
91
158
  export function setupDnsRecords(instance, scope, id, props) {
92
159
  if (!instance.cdk?.distribution ||
93
160
  typeof props.customDomain !== "object" ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infoxchange/make-it-so",
3
- "version": "2.8.1",
3
+ "version": "2.9.0-internal-testing-set-http-proxy-env-var.2",
4
4
  "description": "Makes deploying services to IX infra easy",
5
5
  "repository": "github:infoxchange/make-it-so",
6
6
  "type": "module",
@@ -13,6 +13,7 @@ import {
13
13
  setupDnsRecords,
14
14
  setupDomainAliasRedirect,
15
15
  setupVpcDetails,
16
+ setupDefaultEnvVars,
16
17
  } from "../lib/site/support.js";
17
18
 
18
19
  type ConstructScope = ConstructorParameters<typeof NextjsSite>[0];
@@ -26,6 +27,7 @@ export class IxNextjsSite extends NextjsSite {
26
27
  props: ConstructProps = {},
27
28
  ) {
28
29
  if (ixDeployConfig.isIxDeploy) {
30
+ props = setupDefaultEnvVars(scope, id, props);
29
31
  props = setupVpcDetails(scope, id, props);
30
32
  props = setupCustomDomain(scope, id, props);
31
33
  props = setupCertificate(scope, id, props);
@@ -16,6 +16,7 @@ const envVars = {
16
16
  smtpHost: process.env.SMTP_HOST ?? "",
17
17
  smtpPort: process.env.SMTP_PORT ?? "",
18
18
  clamAVUrl: process.env.CLAMAV_URL ?? "",
19
+ vpcHttpProxy: process.env.VPC_HTTP_PROXY ?? "",
19
20
  } satisfies Record<string, string | boolean>;
20
21
 
21
22
  const ixDeployConfigSchema = z
@@ -39,6 +40,7 @@ const ixDeployConfigSchema = z
39
40
  smtpHost: z.string().min(1),
40
41
  smtpPort: z.coerce.number().int(),
41
42
  clamAVUrl: z.string().url(),
43
+ vpcHttpProxy: z.string().url(),
42
44
  } satisfies Record<keyof typeof envVars, unknown>)
43
45
  .strip();
44
46
 
@@ -69,6 +71,7 @@ const nonIxDeployConfigSchema = z
69
71
  isNaN(parseInt(val, 10)) ? undefined : parseInt(val, 10),
70
72
  ),
71
73
  clamAVUrl: z.string(),
74
+ vpcHttpProxy: z.string(),
72
75
  } satisfies Record<keyof typeof envVars, unknown>)
73
76
  .strip();
74
77
 
@@ -2,6 +2,7 @@ import { Construct } from "constructs";
2
2
  import {
3
3
  NextjsSite,
4
4
  NextjsSiteProps,
5
+ Stack,
5
6
  StaticSite,
6
7
  StaticSiteProps,
7
8
  } from "sst/constructs";
@@ -13,6 +14,7 @@ import { IxDnsRecord } from "../../cdk-constructs/IxDnsRecord.js";
13
14
  import { CloudFrontTarget } from "aws-cdk-lib/aws-route53-targets";
14
15
  import { convertToBase62Hash } from "../utils/hash.js";
15
16
  import { type DistributionDomainProps } from "sst/constructs/Distribution.js";
17
+ import type { Plan as SSTPlan } from "sst/constructs/SsrSite.js";
16
18
 
17
19
  export type ExtendedCustomDomains = DistributionDomainProps & {
18
20
  isIxManagedDomain?: boolean;
@@ -111,7 +113,7 @@ export function setupVpcDetails<Props extends ExtendedNextjsSiteProps>(
111
113
  id: string,
112
114
  props: Readonly<Props>,
113
115
  ): Props {
114
- const updatedProps: Props = { ...props };
116
+ let updatedProps: Props = { ...props };
115
117
  const vpcDetails = new IxVpcDetails(scope, id + "-IxVpcDetails");
116
118
  if (!updatedProps.cdk?.server || !("vpc" in updatedProps.cdk.server)) {
117
119
  updatedProps.cdk = updatedProps.cdk ?? {};
@@ -119,6 +121,7 @@ export function setupVpcDetails<Props extends ExtendedNextjsSiteProps>(
119
121
  ...updatedProps.cdk.server,
120
122
  vpc: vpcDetails.vpc,
121
123
  };
124
+ updatedProps = addHttpProxyEnvVars(scope, id, updatedProps) as Props;
122
125
  }
123
126
  if (
124
127
  !updatedProps.cdk?.revalidation ||
@@ -133,6 +136,96 @@ export function setupVpcDetails<Props extends ExtendedNextjsSiteProps>(
133
136
  return updatedProps;
134
137
  }
135
138
 
139
+ /**
140
+ * Adds HTTP proxy environment variables to the provided site props.
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.
144
+ */
145
+ export function addHttpProxyEnvVars<Props extends ExtendedNextjsSiteProps>(
146
+ scope: Construct,
147
+ id: string,
148
+ props: Readonly<Props>,
149
+ proxyEnvVars?: Record<string, string>,
150
+ ): Props {
151
+ const updatedProps: Props = { ...props };
152
+
153
+ updatedProps.cdk = updatedProps.cdk ?? {};
154
+ const oldTransform = updatedProps.cdk.transform;
155
+ updatedProps.cdk.transform = (plan: SSTPlan) => {
156
+ oldTransform?.(plan);
157
+
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
+ for (const origin of Object.values(plan.origins)) {
175
+ if (!("function" in origin) || !origin.function.environment) {
176
+ continue;
177
+ }
178
+ Object.assign(origin.function.environment, proxyEnvVars);
179
+ }
180
+ };
181
+ return updatedProps;
182
+ }
183
+
184
+ export function setupDefaultEnvVars<Props extends ExtendedNextjsSiteProps>(
185
+ scope: Construct | Stack,
186
+ id: string,
187
+ props: Readonly<Props>,
188
+ ): Props {
189
+ let updatedProps: Props = { ...props };
190
+ // NextjsSite functions to not use default env var unfortunately so we have to
191
+ // explicitly set them ourselves https://github.com/sst/sst/issues/2359
192
+ if ("defaultFunctionProps" in scope) {
193
+ for (const funcProps of scope.defaultFunctionProps) {
194
+ const defaultFunctionEnvVars = { ...funcProps.environment };
195
+
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
+ updatedProps.environment = {
221
+ ...defaultFunctionEnvVars,
222
+ ...updatedProps.environment,
223
+ };
224
+ }
225
+ }
226
+ return updatedProps;
227
+ }
228
+
136
229
  export function setupDnsRecords<
137
230
  Instance extends NextjsSite | StaticSite,
138
231
  Props extends ExtendedStaticSiteProps | ExtendedNextjsSiteProps,